Reputation: 180
I'm trying to connect to an old database that has its own equally old ODBC driver (which is no longer maintained)
# The driver is 32 bit, so I'm using Python 3.8.7 (32bit)
con = pyodbc.connect(r"Driver={CSI RBM 4.02 ODBC Driver};Dbq=" + database_path + ";Server=localhost")
But I'm getting this error:
[08001] [Microsoft][ODBC Driver Manager] The driver doesn't support the version of ODBC behavior that the application requested (see SQLSetEnvAttr).
According to https://knowledgebase.progress.com/articles/Article/000033360 it means:
This error indicates that an application requested ODBC 3.x behavior however the driver was only ODBC 2.x compliant.
Which I assume means that Python or Pyodbc is using ODBC 3.x and the driver is using 2.x.
So if I've assumed all that correctly, then my question is how can I force Pyodbc to use ODBC 2.x, or is there any other way I can connect to this database using Python?
Any other helpful information would be appreciated too
Upvotes: 0
Views: 548
Reputation: 21
You can build it from source.
In the /src/pyodbcmodule.cpp file about at the 330 line change SQL_OV_ODBC3 to SQL_OV_ODBC2 then build and install. I also have and ancient odbc driver what only works with SQL_OV_ODBC2 but hangs every time with SQL_OV_ODBC3.
/src/pyodbcmodule.cpp ~line 330
if (!SQL_SUCCEEDED(SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC2, sizeof(int) ) ) )
{
PyErr_SetString(PyExc_RuntimeError, "Unable to set SQL_ATTR_ODBC_VERSION attribute.");
return false;
}
You can find the source code and documentation for building from sourc here: https://github.com/mkleehammer/pyodbc/wiki/Building-pyodbc-from-source
python setup.py build
python setup.py install
For driver testing you can use the ODBC Test tool from Microsoft.
You can try out any settings of the ODBC driver without writing any code.
https://learn.microsoft.com/en-us/sql/odbc/odbc-test?view=sql-server-ver15 https://www.microsoft.com/en-us/download/details.aspx?id=21995
Upvotes: 2