result = None with pyodbc.connect('DRIVER={SQL Server};SERVER=mydb;DATABASE=solarwinds;Trusted_Connection=True', timeout=1) as cnxn: cursor = cnxn.cursor() result = cursor.execute(query).fetchall()