0

I'm on Mac OS 10.7.5 . I want to connect to an MS SQL db from python2.7. To connect, I've installed and configured FreeTDS and unixodbc. After these, I've installed pyodbc 3.0.10 library through pip.

In the previous versions, pyodbc on Mac installations were compiled to use iODBC, so to make the pyodbc module use unixodbc, some modifications needed to be done before compiling the module. But the later versions (including 3.0.10) are compiled to use unixodbc by default.

After configurations, I've managed to connect to the db using isql, which shows that my unixodbc configurations are in order. But when I try to connect to the db on python as follows;

pyodbc.connect('DSN=DSN;UID=USER;PWD=PASS')

I get the following error:

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

Looks like it is trying to use iODBC. What could be causing this?

EDIT: My config files:

freetds.conf:

[SERVERNAME]
    host = DBID.database.windows.net
    tds version = 7.1
    port = 1433

odbcinst.ini

[FreeTDS]
Description = FreeTDS
Driver=/usr/local/lib/libtdsodbc.so
Setup=/usr/local/lib/libtdsodbc.so

odbc.ini

[DSN]
Description = "DESC"
Driver = FreeTDS
Servername = SERVERNAME
Port = 1433
Database = DBNAME
Ozgur Akcali
  • 5,264
  • 2
  • 31
  • 49
  • I can connect to the db through pyodbc after upgrading to Mac OS 10.10.5, but I still have no solution to make this setup work on Mac OS 10.7.5 – Ozgur Akcali Aug 19 '15 at 13:42

1 Answers1

0

I've always had better luck connect directly with options:

pyodbc.connect('DRIVER={FreeTDS};SERVER=dbserver.domain.com;PORT=1433;DATABASE=yourdb;UID=youruser;PWD=yourpassword;TDS_Version=7.2;')

Can you give that a try? If that doesn't work, please include your freetds.conf, odbc.ini and odbcinst.ini files so we can repro. Good luck!

FlipperPA
  • 13,607
  • 4
  • 39
  • 71
  • this leads to another error message: pyodbc.Error: ('00000', '[00000] [iODBC][Driver Manager]dlopen({FreeTDS}, 6): image not found (0) (SQLDriverConnect)'), I've edited the question to include the config files – Ozgur Akcali Aug 18 '15 at 08:41