Troubleshooting
Problem
Use of a null pointer for the OutConnectionString parameter and StringLength2Ptr parameter may result in an SQL_ERROR return code with SQL state of HY009.
Resolving The Problem
Some SQL CLI applications that use SQLDriverConnect do not require the completed connection string. These applications might specify a null pointer for the OutConnectionString parameter and StringLength2Ptr parameter. Although this works on other platforms including Microsoft ODBC and other IBM® DB2® families this will result in a SQL_ERROR return code with SQL state of HY009 when executed on IBM i.
This restriction is documented in the V5R1 (and later) IBM i documentation:
HY009 Invalid argument value
The argument InConnectionString, OutConnectionString, or
StringLength2PTR was a null pointer.
Note that the sample in the documentation is not correct.
rc = SQLDriverConnect(*hdbc,
(SQLHWND) NULL,
con_str,
SQL_NTS,
NULL, 0, NULL,
SQL_DRIVER_NOPROMPT);
Rather, declare a variable for the output string and output string return length. A corrected version is similar to the following:
rc = SQLDriverConnect (*hdbc,
NULL,
szConStr,
SQL_NTS,
szConStrOut,
sizeof(szConStrOut),
&ConStrOut
SQL_DRIVER_NOPROMPT);
This restriction is documented in the V5R1 (and later) IBM i documentation:
HY009 Invalid argument value
The argument InConnectionString, OutConnectionString, or
StringLength2PTR was a null pointer.
Note that the sample in the documentation is not correct.
rc = SQLDriverConnect(*hdbc,
(SQLHWND) NULL,
con_str,
SQL_NTS,
NULL, 0, NULL,
SQL_DRIVER_NOPROMPT);
Rather, declare a variable for the output string and output string return length. A corrected version is similar to the following:
rc = SQLDriverConnect (*hdbc,
NULL,
szConStr,
SQL_NTS,
szConStrOut,
sizeof(szConStrOut),
&ConStrOut
SQL_DRIVER_NOPROMPT);
[{"Type":"MASTER","Line of Business":{"code":"LOB68","label":"Power HW"},"Business Unit":{"code":"BU070","label":"IBM Infrastructure"},"Product":{"code":"SWG60","label":"IBM i"},"ARM Category":[{"code":"a8m0z000000cwEgAAI","label":"Data Access-\u003ESQL CLI"}],"ARM Case Number":"","Platform":[{"code":"PF012","label":"IBM i"}],"Version":"All Versions"}]
Historical Number
27655054
Was this topic helpful?
Document Information
More support for:
IBM i
Component:
Data Access->SQL CLI
Software version:
All Versions
Operating system(s):
IBM i
Document number:
640373
Modified date:
06 January 2025
UID
nas8N1016907
Manage My Notification Subscriptions