Reputation: 21
Attempting to connect to an Azure SQL database, most other configurations I've tried result in an instant error:
Client unable to establish connection (0) (SQLDriverConnect)')
But this one I'm currently trying times out and is the closest I've got:
cnxn = pyodbc.connect(driver='{ODBC Driver 17 for SQL Server}', server='tcp:mydatabase.database.windows.net:1433', database='MyDatabase', user='username', password='password')
pyodbc.OperationalError: ('HYT00', '[HYT00] [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired (0) (SQLDriverConnect)')
Upvotes: 1
Views: 862
Reputation: 1
The port defined on the server attribute is separated by comma and not colon.
Driver={ODBC Driver 1x for SQL Server};Server=[tcp]:{serverName}.database.windows.net[,1433]; (...)
You can check a sample of the connection string on the connections string blade on your database page on Azure Portal.
Upvotes: 0
Reputation: 8301
There is no requirement for the connection string to include the default SQL Server port, which is 1433.
Add server name without tcp
, use tcp:
before quotes of servername, Server name format is servername.database.windows.net
Example String
pyodbc.connect('DRIVER='+driver+';SERVER=tcp:'+server+';DATABASE='+database+';UID='+username+';PWD='+ password)
Upvotes: 0