Connecting to Informix using pyobbc on Windows
I am trying to write a process in python that needs to be portable between different database environments. One of the environments it needs to be connected to is Informix.
I was looking for how to connect to Informix in Python and came across both InformixDB and ibm_db {, _ sa} which seem overly difficult to use (and I tried and tried and just couldn't get them to work).
I'm trying (again) to get this to work with pyodbc, but can't connect to the database from Windows:
set INFORMIXDIR="C:\Program Files\IBM Informix Client SDK"
set CLIENT_LOCALE=en_US.CP1252
set DB_LOCALE=en_US.819
python
Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:18:40) [MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import pyodbc
>>>
>>> cnxn = pyodbc.connect(dsn='devdb')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
pyodbc.Error: ('HY000', '[HY000] [Informix][Informix ODBC Driver][Informix]Unspecified System Error = -23101. (-23101) (SQLDriverConnect)')
From what I found, Error -23101 is caused by an incorrect locale match, however these are the same values โโused in the ODBC configuration as well as any other Informix related utility I have at my disposal.
I am at a loss to figure out how to connect to Informix and cannot think of more search terms to try and figure out this problem. How difficult it can be to use ODBC - just about every other language I know has no problem with it!
Note . To be clear, the ODBC connection is set up correctly and works with other ODBC based applications (I can connect using QTODBC or Perl DBI).
Thanks in advance for your help.
Edit : Heh, I'm not enough authority to attach an image yet, but I have uploaded it at http://wraeth.id.au/wp-content/uploads/2014/10/odbcad32.png if you want to take a look.
Edit 2 :
- Updated to ActivePython-3.3.4 with no changes
- Created a symbolic link to the IFX ClientSDK directory to remove spaces in the path, resulting in "driver not throwing an error"
- Confirmed
DB_LOCALE
-en_US.819
by checking the tablesysdbslocale
in the database.
Also confirmed to be %INFORMIXDIR%
installed on a valid CSDK installation:
> mklink /D informix "C:\Program Files\IBM Informix Client SDK"
> set INFORMIXDIR=C:\informix
> dir %INFORMIXDIR%\gls
Volume in drive C has no label
Volume Serial Number is 808D-98FF
Directory of C:\informix\gls
19/09/2013 04:50 PM <DIR> .
19/09/2013 04:50 PM <DIR> ..
19/09/2013 04:50 PM <DIR> cm3
19/09/2013 04:50 PM <DIR> cv9
19/09/2013 04:50 PM <DIR> dll
19/09/2013 04:50 PM <DIR> etc
19/09/2013 04:50 PM <DIR> lc11
Using a symbolic link INFORMIXDIR
still prevents it from being connected:
ActivePython 3.3.4.1 (ActiveState Software Inc.) based on
Python 3.3.4 (default, Feb 25 2014, 15:11:05) [MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os, pyodbc
>>> os.path.exists(
... os.path.join(
... os.environ.get('INFORMIXDIR'),
... 'gls'
... )
... )
True
>>> cnxn = pyodbc.connect(dsn='devdb', uid='user', pwd='password')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
pyodbc.Error: ('HY000', 'The driver did not supply an error!')
Decision
Removing and reinstalling the client SDK to a path that has no spaces ( C:\informix
) seems to fix the problem.
source to share
This should be a comment, but too long.
Until I can reproduce your error, I have some ideas.
-
Reinstall the ClientSDK and install it to the directory
c:\informix
by setting it as%INFORMIXDIR%
. This should change the ODBC registry entries about the driver:[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\IBM INFORMIX ODBC DRIVER] "Driver"="C:\\informix\\bin\\iclit09b.dll" "Setup"="C:\\informix\\bin\\iclit09b.dll"
and about the database (
devdb
is my DSN)[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\devdb] "Driver"="C:\\informix\\bin\\iclit09b.dll"
(these entries refer to 32-bit Windows)
I advise him to read the answers and comments: Informix connection works through Windows, but not through Cygwin
-
If you have ActiveState Python, you can use a module
odbc
insteadpyodbc
. Is is part of the packagewin32
and only works on Windows, but maybe it can connect to your database. You can open the database with:import odbc cnxn = odbc.odbc('devdb/user/password')
-
If some ODBC software works, you can enable ODBC tracing and compare traces. It would be especially helpful if you can connect to the module
odbc
but not frompyodbc
.
source to share