Hi guys,
Im doing a project for work and I have a function to connect to our Azure SQL Server database. I am using the right connection string based on the Azure which is Driver={ODBC Driver 18 for SQL Server};Server=;Database=;Uid={your_user_name};Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;Authentication=ActiveDirectoryIntegrated.
The weird thing is that this connection worked for almost 2 months now until yesterday where I started getting an error message.
The error message is shown below:
Error connecting to the database: ('HY000', '[HY000] [Microsoft][ODBC Driver 18 for SQL Server]An unknown error has occurred. Detailed error information is not available. (0) (SQLDriverConnect); [HY000] [Microsoft][ODBC Driver 18 for SQL Server]Invalid connection string attribute (0); [HY000] [Microsoft][ODBC Driver 18 for SQL Server]Invalid connection string attribute (0); [HY000] [Microsoft][ODBC Driver 18 for SQL Server]An unknown error has occurred. Detailed error information is not available. (0)')
I checked with our infrastructure and apparently nothing is blocking it. I could connect using SSMS/Azure Studio.
Can someone please review my code and tell me im not going crazy here cause I cant see anything wrong with it
Code snippet:
server = '*'
database = '*'
username = '*'
driver = 'ODBC Driver 18 for SQL Server'
# Construct connection string
conn_str = (f"""DRIVER={{{driver}}};
server={server};
database={database};
Uid={username};
Encrypt=yes;
TrustServerCertificate=no;
Connection Timeout=30;
Authentication=ActiveDirectoryIntegrated;
""")
connection = pyodbc.connect(conn_str)
return connection
connection = connect_to_db()
cursor = connection.cursor()```