db connection string timeout 1

db connection string timeout

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()

Here is what the above code is Doing:
1. Connect to the database using pyodbc
2. Create a cursor object
3. Execute the query and fetch all the results
4. Store the results in a variable

Similar Posts