I'm stuck and can't figure out a workable way to connect asynchronously to an Azure SQL database using Python.
I've tried asyncio, pyodbc and asyncpg to no avail.
I think this is close...
import asyncio
import pyodbc
async def query_azure_sql_db():
connection_string = 'Driver={ODBC Driver 17 for SQL Server};Server=tcp:<mySERVER>.database.windows.net,1433;Database=sqldbstockdata;Uid=<myUN>;Pwd=<myPW>;Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;'
async with pyodbc.connect(connection_string) as conn:
async with conn.cursor() as cursor:
query = 'SELECT * FROM dbo.<myTABLE>'
await cursor.execute(query)
results = cursor.fetchall()
return results
loop = asyncio.get_event_loop()
results = loop.run_until_complete(query_azure_sql_db())
print(results)
But results in this cryptic error: AttributeError: __aenter__
I'm open to other libraries.
Any help is appreciated.