Answer the question
In order to leave comments, you need to log in
Is there an asynchronous driver for Microsoft SQL Server in python, for sqlalchemy?
I want to try to write asynchronous queries to the database through sqlalchemy, but when I try, it swears that there is no asynchronous driver, please tell me how to solve this problem?
Or what driver to put?
async def async_main():
connection_string = f"DRIVER={{ODBC Driver 17 for SQL Server}};" \
f"SERVER={DB_HOST};DATABASE={DATABASE};" \
f"UID={DB_USER};PWD={DB_PASS}"
connection_url = URL.create("mssql+pyodbc", query={"odbc_connect": connection_string})
engine = create_async_engine(connection_url,
echo=True) # при необходимости, включения/выключения логов запросов меняется параметр echo
async with engine.begin() as conn:
await conn.run_sync(meta.create_all)
async with engine.connect() as conn:
result = await conn.execute(select(CT_DOC_CARDS).where(CT_DOC_CARDS.c.NUMBER_DOC == "BMK2\\173993"))
print(result.fetchall())
await engine.dispose()
asyncio.run(async_main())
sqlalchemy.exc.InvalidRequestError: The asyncio extension requires an async driver to be used. The loaded 'pyodbc' is not async.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question