pyODBC:在Windows中指定驱动程序的位置 [英] pyODBC: specify location of driver in Windows
问题描述
是否可以指定pyodbc在哪里寻找SQL驱动程序?
我有一个python应用程序,该应用程序需要 SQL Native Client 10.0驱动程序才能连接到SQL数据库。所以我的连接字符串如下:
dsn ='DRIVER = {SQL Server Native Client 10.0}; SERVER = localhost; DATABASE = mydatabase; UID = sa; PWD = mypasswd'
con = pyodbc.connect(dsn)
with con:
#做某事
一个主要的缺点(至少对我来说)是,必须在计算机上安装SQL Native Client 10.0驱动程序,并且需要管理员权限。但是,我希望用户无需安装即可运行我的python应用程序。
在互联网上进行了快速研究之后,似乎SQL Native Client 10.0依赖于驻留在C:\Windows\中的简单DLL(sqlncli10.dll)。 \系统32。那么有可能告诉pyodbc在哪里寻找合适的SQL驱动程序?
据我了解,pymssql做类似的事情(FreeTDS驱动程序包含在Python软件包中,因此不需要进一步安装驱动程序)。但是,我认为pyobc比pymssql更稳定(社区似乎也更活跃),因此我想使用pyodbc与我的数据库进行通信。
如果您的应用程序实际使用特定于
的功能 Driver = {SQL Server Native Client 10.0}
然后需要在客户端系统上正确安装驱动程序。但是,如果您只需要与SQL Server的基本连接,则
Driver = {SQL Server}
已包含在标准Windows安装中,并且可用于32位和64位应用程序。 / p>
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.
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.
这篇关于pyODBC:在Windows中指定驱动程序的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!