I am trying to connect to a remote db2 server using my code in c++. I am able to connect to the db2 server using the db2CLP to connect the server. I have configured the db2cli using the following commands:
db2cli writecfg add -dsn alias -database BLUDB -host hostname -port 50000
and even validated it using
db2cli validate -dsn alias -connect -user userid -passwd password
I am getting an error code of : Native Error Code = -1531 when i use the function
SQLConnect(hdbc,
(SQLWCHAR *)db1Alias,
SQL_NTS,
(SQLWCHAR *)user,
SQL_NTS,
(SQLWCHAR *)pswd,
SQL_NTS);
And no error messages. Can anyone point out if I am doing something wrong?
I have checked the error codes in IBM's page and did not find -1531 in its list. (https://www.ibm.com/support/knowledgecenter/en/SSEPEK_11.0.0/codes/src/tpc/db2z_n.html)
Here is the snippet of the code i am using : I had picked this up from ibm's sample section(https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.apdv.sample.doc/doc/cli/s-dbconn-c.html)
#define DBC_HANDLE_CHECK(hdbc, cliRC) \
if (cliRC != SQL_SUCCESS) \
{ \
SQLWCHAR message[SQL_MAX_MESSAGE_LENGTH + 1]; \
SQLWCHAR sqlstate[SQL_SQLSTATE_SIZE + 1]; \
SQLINTEGER sqlcode; \
SQLSMALLINT length, i; \
i = 1; \
/* get multiple field settings of diagnostic record */
while (SQLGetDiagRec(SQL_HANDLE_DBC, \
hdbc, \
i, \
sqlstate, \
&sqlcode, \
message, \
SQL_MAX_MESSAGE_LENGTH + 1, \
&length) == SQL_SUCCESS) \
{ \
printf("\n SQLSTATE = %s\n", sqlstate); \
printf(" Native Error Code = %d\n", sqlcode); \
printf("Error Meassgaes:%s\n", message); \
i++; \
} \
printf("-------------------------\n"); \
if (rc != 0) return rc; \
}
/* allocate a database connection handle */
cliRC = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);
ENV_HANDLE_CHECK(henv, cliRC);
printf("\n Connecting to the database %s ...\n", db1Alias);
/* connect to the database */
cliRC = SQLConnect(hdbc,
(SQLWCHAR *)db1Alias,
SQL_NTS,
(SQLWCHAR *)user,
SQL_NTS,
(SQLWCHAR *)pswd,
SQL_NTS);
DBC_HANDLE_CHECK(hdbc, cliRC);
Actual result
Native Error Code = -1531
Error Meassgaes:[
-------------------------
Expected :the connection should be established.