Photo by Alexander Sinn on Unsplash
First install FreeTDS on your Linux:
apt install tdsodbc freetds-bin
Next configure FreeTDS by adding this to /etc/odbcinst.ini
[FreeTDS]
Description=FreeTDS
Driver=/usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup=/usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
Finally activate
odbcinst -i -d -f /etc/odbcinst.ini
And now I can run pyodbc in my code
import pyodbc
connection = pyodbc.connect('DRIVER={FreeTDS};'
'Server='+dbhost+';'
'Database='+dbname+';'
'UID='+dbuser+';'
'PWD='+dbpass+';'
'TDS_Version=8.0;'
'Port=1433;')
cursor = connection.cursor()
cursor.execute("SELECT * FROM tablename; ")
for row in cursor:
print(row)