SQLAllocHandle of the driver on SQL_HANDLE_ENV failed when connecting to IBM-DB2 database
11 views (last 30 days)
Show older comments
MathWorks Support Team
on 5 Aug 2022
Answered: MathWorks Support Team
on 25 Aug 2022
In Matlab R2022a, we are unable to open a connection to our IBM-DB2 database. With the previous version R2021b, this is not a problem.
We are executing the following command in R2021b and R2022a
>> cs = 'dsn=DB2G;UID=SID#SFG;PWD=xxxxxxx;';
>> myConnection = actxserver('ADODB.Connection');
>> set(myConnection , 'ConnectionTimeout' ,0 )
>> set( myConnection , 'CursorLocation' , 'adUseClient')
>> invoke(myConnection , 'Open' , cs)
Resulting Error in R2022a
Error using COM.ADODB_Connection/Open
Invoke Error, Dispatch Exception:
Source: Microsoft OLE DB Provider for ODBC Drivers
Description: [Microsoft][ODBC-driver management] SQLAllocHandle of the driver on SQL_HANDLE_ENV failed
Successful output in R2021b
Properties: [1×1 Interface.00000504_0000_0010_8000_00AA006D2EA4]
ConnectionString: 'Provider=MSDASQL.1;'
CommandTimeout: 30
ConnectionTimeout: 0
Version: '10.0'
Errors: [1×1 Interface.00000501_0000_0010_8000_00AA006D2EA4]
DefaultDatabase: 'DB2G'
IsolationLevel: 'adXactCursorStability'
Attributes: 0
CursorLocation: 'adUseServer'
Mode: 'adModeUnknown'
Provider: 'MSDASQL.1'
State: 1
Both runs are on the same machine: Windows 10 Enterprise – Version 1909.
The same problem occurs on a second equivalent machine where we have installed R2022a.
We use an ODBC driver from IBM and not a Windows Db2 client. The Database (DB2) is on the mainframe not on windows.
The ODBC Driver is installed in 2021. The ODBC driver is : IBM DB2 ODBC DRIVER version 11.05.5010.1723
The connection also fails with the same error when using the Database Explorer App.
Accepted Answer
MathWorks Support Team
on 5 Aug 2022
This is a bug in the DB2 driver that was exposed by changes in MATLAB R2022a. For some context, see this Stack Overflow page, specifically the solution:
There is a fairly new Windows feature that enables UTF-8 worldwide language support for text. In R2021b and prior, MATLAB would depend on the user turning this on to properly support non-ASCII characters. However, in R2022a, the MATLAB process will enable this feature always, so that any characters would be supported properly in MATLAB no matter what the Windows setting is. From the stack overflow page, we can see that there is a bug where connecting to DB2 fails when the UTF-8 support setting is turned on. Since this feature is always in effect in R2022a, MATLAB can't connect using DB2's ODBC driver due to this bug.
In order to demonstrate that this is the issue, you can try turning on the Windows Features, and try connecting in 21b, you should see the same error that you are getting in R2022a.
Unfortunately, this is an issue from the driver's side, so there's not much we can do on our end to fix this. I would suggest the following:
1) Switch to DB2's JDBC driver if possible
2) Stay with a release before R2022a
3) Submit a bug report to IBM regarding the incompatibility. We tried this from our end, but it appears you need a paid IBM account.
0 Comments
More Answers (0)
See Also
Categories
Find more on Database Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!