pyODBC: specify location of driver in Windows

最后都变了- 提交于 2019-12-10 21:43:21

问题


Is it possible to specify where pyodbc looks for the SQL driver?

I have a python application which needs the 'SQL Native Client 10.0' driver to connect to a SQL database. So my connection string looks like:

dsn = 'DRIVER={SQL Server Native Client 10.0};SERVER=localhost;DATABASE=mydatabase;UID=sa;PWD=mypasswd'

con = pyodbc.connect(dsn) 
with con: 
    #do something

One major disadvantage (at least for me) is, that the SQL Native Client 10.0 driver needs to be installed on the machine and that requires admin privileges. However, I want that the user can run my python application without any install.

After a quick research on the internet, it seems that the SQL Native client 10.0 depends on a simple DLL (sqlncli10.dll) which resides in C:\Windows\System32. So is it possible, to tell pyodbc where it should look for the appropriate SQL driver?

As from my understanding, pymssql does something similar (the FreeTDS driver is included in the Python package, so no further driver installation is required). However, in my opinion pyobc is a more stable than pymssql (and the community seems to be more active too), so I would like to use pyodbc to communicate with my database.


回答1:


If your application actually uses features specific to

Driver={SQL Server Native Client 10.0}

then that driver needs to be installed properly on the client system. However, if you just need basic connectivity to SQL Server then

Driver={SQL Server}

is included with a standard Windows install and is available to both 32-bit and 64-bit applications.



来源:https://stackoverflow.com/questions/19401566/pyodbc-specify-location-of-driver-in-windows

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