Reputation: 246083
I am writing a C program on Linux that connects to a DB2 LUW database using the CLI driver 11.5.
I am successful in connecting to a local database on port 50000 with the following SQLDriverConnect
call:
SQLDriverConnect(
hdbc, /* a valid connection handle */
NULL, /* no Window handle */
(SQLCHAR *)"DATABASE=testdb;UID=username;PWD=password",
SQL_NTS, /* the connect string is NUL-terminated */
NULL, /* don't care about the completed connect string... */
0,
NULL, /* ...or its length */
SQL_DRIVER_NOPROMPT /* don't prompt me */
);
But if I specify a host name and a TCP port, as described in the documentation page I linked to:
"DATABASE=testdb:localhost:50000;UID=username;PWD=password"
I get the error message
[IBM][CLI Driver] SQL30061N The database alias or database name "TESTDB:LOCALHOST:50000" was not found at the remote node. SQLSTATE=08004
Does anybody know how to connect to a remote DB2 database?
db2level
gives me
DB21085I This instance or install (instance name, where applicable: "*") uses
"64" bits and DB2 code release "SQL11054" with level identifier "0605010F".
Informational tokens are "DB2 v11.5.4.0", "s2006161200", "DYN2006161200AMD64",
and Fix Pack "0".
Product is installed at "/usr/db2".
Upvotes: 1
Views: 1287
Reputation: 308
Take a look at the .\samples\cli\dbconn.c sample source code.
It has 3 different ways to connect and covers the C part...
But it seems your issue is that your connection string is mal-formed
DATABASE=XXX:localhost:5000
is not a valid db2 cli connection string. Per the error message, it's interpreting everything after database=
as the DB name. TESTDB:LOCALHOST:50000
.
Per documentation:
To make a connection to the database in a CLI application, you can perform one of the listed actions:
* Call SQLDriverConnect with a connection string that contains:
Database=db1; Protocol=tcpip; Hostname=11.22.33.44; Servicename=56789;
Upvotes: 2