Does anyone know a way to connect to a SQL Server database from Python without installing a driver like ODBC? I need to do that on a customer server. I already established a connection from Python to SQL Server via pymssql , but since the project is being discontinued, I am looking for an alternative.
Is it for example possible to link a dll with odbc driver? If yes, where would I get it and how could I link it to Python?
2条答案
按热度按时间noj0wjuj1#
as of 2021-08, you can still try with pymssql( https://github.com/pymssql/pymssql ) the project no longer depreciated, is active again.
if using conda, you can install from conda-forge
conda install pymssql
if
import pymssql
shows error:libiconv.so.2: cannot open shared object file
, you can also install libiconv by condaconda install libiconv
code example:
6vl6ewon2#
This may be an old question, but may be relavent to many like me. I was able to get that worked by doing the below steps. If its the Windows machine, the below listed steps should work, to get python connects to MS Sql server without ODBC setting.
Need to install/setup
SQL Server Native Client 11.0
at least, as thats the last version from SQL2012 native client tool. Since 2016, its no longer shipped and rather prefer to usemsoledbsql 18.xx.xx
or above.You can download this from internet by searching for this or, i used Choco to install this for me.
choco install SQL2012.NativeClient
. If you dont know or dont have choco, just search and download the MSI from MSFT site only.Ensure you see a version in the ODBC drivers tab like this
Ensure you have your connection string refers that exact driver name like,
mssql+pyodbc://{YOUR-SQL-SERVER-INSTANCe}?driver=SQL+Server+Native+Client+11.0
Certainly your python needs pyodbc library and sqlalchemy to use this.