Connect Python to SQL Server without ODBC

Viewed 2656

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?

1 Answers

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:

import pymssql

conn = pymssql.connect(server="127.0.0.1", port="33412", user="reader", password="passwd", database="db_name")
cursor = conn.cursor()
cursor.execute('SELECT TOP 10 * FROM table_name')
data=cursor.fetchall()
Related