Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pypyodbc: Can't open lib 'FreeTDS' : file not found") error when trying to connect to SQL server

I'm trying to connect to a SQL Server using Pypyodbc on Mac and I'm getting the following error:

pypyodbc.DatabaseError: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'FreeTDS' : file not found")

I have installed freeTDS and unixodbc

brew install unixodbc
brew install freetds

and here is my connection String with dummy data:

connection_String = "Driver=FreeTDS;Server=123.12.12.12;tds_version=7.2;Database=db_db;Uid=username:pwd=password:port=1433"
like image 573
Mo. Avatar asked Feb 17 '15 16:02

Mo.


2 Answers

Check your /etc/odbcinst.ini or it could be under /etc/unixODBC/odbcinst.ini

In your connection string you have something like this "DRIVER=FreeTDS" there needs to be an entry in that file like the following. You may need to change your driver location.

[FreeTDS]
Description             = FreeTDS unixODBC Driver
Driver          = /usr/lib64/libtdsodbc.so.0
Setup           = /usr/lib64/libtdsodbc.so.0
UsageCount              = 1
like image 77
KtmDan Avatar answered Nov 15 '22 21:11

KtmDan


First, you can use pymssql which doesn't require configuring unixODBC, which is the problem here.

To configure unixODBC with FreeTDS, do the following: http://www.unixodbc.org/doc/FreeTDS.html

There's a tool that comes with FreeTDS, tsql. Use it to test your connection string. It's a very bare bones tool and something of a pain. :-/

Finally, there's a similar question with other problems in StackOverflow: How do I configure pyodbc to correctly accept strings from SQL Server using freeTDS and unixODBC?

like image 10
Javier Avatar answered Nov 15 '22 19:11

Javier