JKC
JKC

Reputation: 109

IBM DB2 ODBC driver 64bit fails to load

When I try to connect to the DB2 database with the 64bit DB2 ODBC driver, the API call fails. With 32bit driver its fine.

Here is the code:

TCHAR dsn[] = _T("DSN=ODBCDB2"), connStringOut[100] = _T("");
SQLSMALLINT connStringOutSize = 0;
SQLRETURN rc = SQLDriverConnect(connHandle, NULL, (SQLTCHAR *)dsn, _tcslen(dsn), connStringOut, sizeof(connStringOut) / sizeof(TCHAR), &connStringOutSize, SQL_DRIVER_NOPROMPT);

//rc = -1
//Error message: Specified driver could not be loaded due to system error  1114: A dynamic link library (DLL) initialization routine failed. (IBM DB2 ODBC DRIVER - DB2COPY1, C:\PROGRA~1\IBM\SQLLIB\BIN\DB2CLIO.DLL)

Environment Details:

  • IBM DB2 v11.5.0.1077
  • IBM DB2 ODBC Driver v11.5.0.1077 (32-bit)
  • ODBC v3.8
  • VC++ (Visual Studio 2017)
  • Windows 10 64-bit

Any help is much appreciated. Thanks!

Upvotes: 2

Views: 8586

Answers (2)

djordjetane
djordjetane

Reputation: 21

Had the same problem. You must change the default DLL in registry. Enter regedit HKEY_CURRENT_USER-> Software-> ODBC-> ODBC.INI -> {Name of your DS}

Change value Driver from DB2CLIO.DLL to DB2CLI64.DLL

Upvotes: 2

JKC
JKC

Reputation: 109

Finally I found the cause of the problem:

When a DSN is added using "ODBC Data Source Administrator", some entries in the registry get created. One of the entry is:

[Computer\HKEY_CURRENT_USER\Software\ODBC\ODBC.INI]
Driver REG_SZ C:\PROGRA~1\IBM\SQLLIB\BIN\DB2CLIO.DLL

For 64bit DSN, the correct DLL is db2cli64.dll.

Don't know why despite using the "64bit ODBC Data Source Administrator" to create the DSN, the DLL in the registry is the wrong one.

Upvotes: 2

Related Questions