Reputation: 91
I am not able to connect to my azure database in python using pyodbc library.
When I pass the connection string in the below format:
*
cnxn = pyodbc.connect(
'DRIVER={SQL Server};'
'SERVER= servername;'
'DATABASE=dbname;'
'username=username;'
'password=password'
)
I get the following error:
line 4, in cnxn = pyodbc.connect( pyodbc.OperationalError: ('08001', '[08001] [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied.
When I pass the connection string in the below format:
*
cnxn = pyodbc.connect(
driver = '{SQL Server}',
server = 'servername',
database = 'dbname',
username = 'username',
password = 'password'
)
I get the following error:
line 4, in cnxn = pyodbc.connect( pyodbc.InterfaceError: ('28000', "[28000] [Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user
Upvotes: 0
Views: 508
Reputation: 91
Below is the correct format of the connection string:
cnxn = pyodbc.connect(
'DRIVER={SQL Server};'
'SERVER= servername;'
'DATABASE=dbname;'
'UID=username;'
'PWD=password'
)
Upvotes: 0
Reputation: 626
In order to give you full answer please add where are trying to connect to the server from: your computer? a server?
Did you make sure that you IP is whitelisted ?
did you tied to connect to the DB with SSMS(sql server management studio) so you know for sure it is not a user/password issue?
A possible solution if you are trying from your windows base computer is to to install ODBC Driver 13&17 and then change your code:
driver = '{ODBC Driver 17 for SQL Server}'
Upvotes: 0