PyOdbc fails to connect to a sql server instance

两盒软妹~` 提交于 2019-12-01 20:44:54

OK, this seems to have resolved the issue

import urllib    
connection_string = "DRIVER={SQL Server};Database=people;SERVER=gagan;UID=sa;PWD=admin1"
connection_string = urllib.quote_plus(connection_string) 
connection_string = "mssql+pyodbc:///?odbc_connect=%s" % connection_string

There are other drivers available in Windows ecosystem, you can try the other 2 as well :)

There are actually two or three SQL Server drivers written and distrubuted by Microsoft: one referred to as "SQL Server" and the other as "SQL Native Client" and "SQL Server Native Client 10.0}".

DRIVER={SQL Server};SERVER=cloak;DATABASE=test;UID=user;PWD=password

DRIVER={SQL Native Client};SERVER=dagger;DATABASE=test;UID=user;PWD=password

DRIVER={SQL Server Native Client 10.0};SERVER=dagger;DATABASE=test;UID=user;PWD=password

Reference: https://code.google.com/p/pyodbc/wiki/ConnectionStrings

EDIT: 1

Since SQLSoup which is written on top of SQLAlchemy you will have to use the following connection string:

"mssql+pyodbc://sa:admin1@mymachinename/mydb"

Reference: http://docs.sqlalchemy.org/en/rel_0_8/dialects/mssql.html#module-sqlalchemy.dialects.mssql.pyodbc

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