问题
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