Sql-server – Can’t connect to ODBC database with pyodbc. Which SQL Server driver should I install on the Raspberry Pi

odbcpythonsql server

I'm trying to connect to a SQL Server database using a python script. I'm using the pyodbc library to connect to it.

cnxn = pyodbc.connect('DRIVER={SQL Driver}; SERVER=192.168.80.30 ;DATABASE=users;UID=data;PWD=xxxx')

When running the script with the above connection configuration I get:

pyodbc.Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found, and no default driver specified (0) (SQLDriverConnect)')

It seems that I don't have the SQLDriver installed. Doing some research I haven't found a driver that works. Which ODBC driver should I install on the Raspberry Pi? I'm using Raspbian.

Best Answer

I believe you are looking for FreeTDS or for pymssql. From pymssql docs:

A simple database interface for Python that builds on top of FreeTDS to provide a Python DB-API (PEP-249) interface to Microsoft SQL Server.