Question

I've been round and round on this for hours. I can't connect to a database via pyodbc, but I can use both tsql and isql to connect.

I'm now simply trying (which is probably wrong, but illustrates my point):

import pyodbc

pyodbc.connect("DRIVER={dev};SERVER=epdbdev01;DATABASE=something;USER=epnet2;OPTION=3;")

and I get this:

Error: ('00000', '[00000] [iODBC][Driver Manager]dlopen({dev}, 6): image not found (0) (SQLDriverConnect)')

I can connect via isql just fine, and for fun:

$ isql -v dev_fail user pass
[IM002][unixODBC][Driver Manager]Data source name not found, and no default driver specified
[ISQL]ERROR: Could not SQLConnect

$ isql -v dev user pass
+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+

you can see that if I use an invalid DSN I can an error, and with the correct DSN I'm in. Now, the error for the incorrect DSN is the same error that I get with pyodbc, so seems something is crossed up.

I struggling with this I've resintalled things a few times and right now my odbc.ini and odbcinst.ini are sym linked from my homebrew installs to my home dir as below:

.freetds.conf -> /usr/local/Cellar/freetds/0.91/etc/freetds.conf
.odbc.ini -> /usr/local/Cellar/unixodbc/2.3.2/etc/odbc.ini
.odbcinst.ini -> /usr/local/Cellar/unixodbc/2.3.2/etc/odbcinst.ini

and finally, my odbc.ini and odbcinst.ini files:

odbc.ini

[dev]
Driver = FreeTDS
Description = please work
ServerName = epdbdev01
UID = user
PWD = pass

odbcinst.ini

[FreeTDS]
Description = FreeTDS
Driver = /usr/local/Cellar/freetds/0.91/lib/libtdsodbc.so
Setup = /usr/local/Cellar/freetds/0.91/lib/libtdsodbc.so
client charset = utf-8

Does pyodbc look for the driver information somewhere that I'm just missing? I'm in the weeds on this one and I've probably crossed something up, but if isql works I would imagine that pyodbc would piggyback on that same connection information, but apparently now.

Was it helpful?

Solution

In the end I put the odbc.ini and the odbcinst.ini at /etc. In addition, I reinstalled freetds from homebrew with the --with-unixodbc command and it worked. Reading this blog by JD Long for the 5th time helped me get the iODBC vs unixODBC disconnect.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top