connect to Azure SQL database via pyodbc

帅比萌擦擦* 提交于 2019-12-05 01:51:18

问题


I use pyodbc to connect to my local SQL database which works withoout problems.

SQLSERVERLOCAL='Driver={SQL Server Native Client 11.0};Server=(localdb)\\v11.0;integrated security = true;DATABASE=eodba;'
cnxn = pyodbc.connect(SQLSERVERLOCAL)   #works

I try the connection to the azure sql database with:

SQLSERVERAZURE='Driver={SQL Server Native Client 10.0};Server=tcp:mydatbase.database.windows.net,1433;Database=mydb;Uid=myuser@myerver;Pwd=mypass;Encrypt=yes;Connection Timeout=30;'
cnxn = pyodbc.connect(SQLSERVERAZURE)   #works not

what gives me the error:

[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')

回答1:


Besides the suggestions that provided by meet-bhagdev who recommended to use pymssql dirve that mentioned in link, to resolve the error: Data source name not found and no default driver specified (0) (SQLDriverConnect)') that encountered, please update your connect string as below to see if it works.

conn = pyodbc.connect('DRIVER={SQL Server};SERVER=yoursqlAzureServer.database.windows.net,1433', user='yourName@yoursqlAzureServer', password='Password', database='DBName')




回答2:


Download ODBC driver from Microsoft website and try installing it. I guess then the problem should disappear. Here is the link: https://www.microsoft.com/en-us/download/details.aspx?id=50420



来源:https://stackoverflow.com/questions/30802199/connect-to-azure-sql-database-via-pyodbc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!