我正在Linux上编写一个C程序,该程序使用CLI驱动程序11.5连接到DB2 LUW数据库。
我通过以下SQLDriverConnect
调用成功连接到端口50000上的本地数据库:
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 */
);
但是,如果我指定了一个主机名和一个TCP端口,则如我链接到的文档页面所述:
"DATABASE=testdb:localhost:50000;UID=username;PWD=password"
我收到错误消息
[IBM][CLI Driver] SQL30061N The database alias or database name "TESTDB:LOCALHOST:50000" was not found at the remote node. SQLSTATE=08004
有人知道如何连接到远程DB2数据库吗?
db2level
给我
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".
看一下。\ samples \ cli \ dbconn.c示例源代码。
它有3种不同的连接方式,涵盖了C部分。
但似乎您的问题是您的连接字符串格式错误
DATABASE=XXX:localhost:5000
不是有效的db2 cli连接字符串。根据错误消息,它将所有内容解释database=
为数据库名称。TESTDB:LOCALHOST:50000
。
每个文档:
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;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句