'Cannot login to SQL database using pyodbc, login failure
Has anyone seen this error before?:
ProgrammingError: ('42000', '[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot open database "TC" requested by the login. The login failed. (4060) (SQLDriverConnect); [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot open database "TC" requested by the login. The login failed. (4060)')
I have verified my credentials and they are 100% correct. As well as, I am using:
python 3.9.7
pyodbc 4.0.0
and when I use:
[x for x in pyodbc.drivers() if x.startswith("ODBC Driver")]
I get:
['ODBC Driver 11 for SQL Server', 'ODBC Driver 17 for SQL Server']
and I'm using SSMS 2014 so ODBC Driver 11 should support that. I am lost as to why this error keeps popping up for my connection string, my connection string is:
cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=' + server + ';DATABASE=' + database + ';UID=' + username + ';PWD=' + password)
So I've verified everything I can think of to this point and it all seems correct, what could the issue be?
Solution 1:[1]
Try changing the driver to explicitly use v11
pyodbc.connect(driver='{SQL Server Native Client 11.0}',
server='Server', database='TC', uid='id',pwd='pass')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mr. Wright |
