请教各位高手, 客户端连接远程 db2 数据库.采用 unixODBC . 基本配置如下:
1. 客户机(linux redhat enterprise 5).安装 unixODBC 包
2. 安装 ibm_data_server_driver_for_odbc_cli_32_linuxia32_v97.tar.gz 驱动包
路径 /home/oracle/cli_driver/.
3. db2驱动路径下 cfg目录的db2cli.ini 配置
[192.168.9.105]
Servicename = db2conn
Database = mydb1
Protocol = TCPIP
uid= db2inst1
pwd= admin
Hostname = 192.168.9.105
Port = 50000
autocommit=0
4. unixODBC odbcinst.ini 配置
[DB2]
Description = DB2 Driver
Driver = /home/oracle/cli_odbc/odbc_cli/clidriver/lib/libdb2.so
FileUsage = 1
DontDLClose = 1
UsageCount = 2
5.
unixODBC odbc.ini配置
[192.168.9.105]
Description = example database connection
Username = db2inst1
Driver = DB2
ReadOnly = 0
6. 以上配置完成后,使用命令: isql -v 192.168.9.105 db2inst1 admin. 能够连接上 db2 server 上的数据库,并能查询操作
7. 写了小程序(c++),使用OTL库, 连接时就报错了,错误如下:
[unixODBC][Driver Manager] Data source name not found, and no default driver specified
IM002
程序如下:
#include
#include
#include
#include
#include
//#define OTL_DB2_CLI // Compile OTL 4/DB2-CLI
//#define OTL_ODBC_UNIX // Compile OTL 4/DB2-CLI
//#define OTL_STL // Turn on STL features and otl_value
//#ifndef OTL_ANSI_CPP
//#define OTL_ANSI_CPP // Turn on ANSI C++ typecasts
//#endif
#define OTL_DB2_CLI
#include "otlv4.h" // include the OTL 4.0 header file
using namespace std;
::db2::otl_connect *m_pDb2Connect; // connect object
::db2::otl_stream *m_pDb2Stream;
/*
// insert rows into table
void insert(void)
{
otl_long_string f2(1000); // define long string variable
db.set_max_long_size(1000); // set maximum long string size for connect object
otl_stream o(10, // buffer size
"insert into test_tab values(:f1,:f2)",
// SQL statement
db // connect object
);
// Total memory consumption for the buffer equals 1000 * 10,
// max_long_size * buffer size
for(int i=1;i<=20;++i)
{
for(int j=0;j<50;++j)
f2[j]='*';
f2[50]='?';
f2.set_len(51);
o<}
}*/
void select(void)
{
char p_strName[100+1] = { 0x00} ;
otl_long_string f2(1000); // define long string variable
m_pDb2Connect->set_max_long_size(1000); // set maximum long string size for connect object
//otl_stream i(10, // buffer size
// "select name from t", // SELECT statement
// db); // connect object
m_pDb2Stream->open(100,"select name from t",*(m_pDb2Connect));
}
int main()
{
db2::otl_connect::otl_initialize(1);
m_pDb2Connect = new db2::otl_connect();
m_pDb2Stream = new db2::otl_stream();
try{
m_pDb2Connect->rlogon("DSN=192.168.9.105;UID=db2inst1;PWD=admin");
//m_pDb2Connect->rlogon(db2inst1/admin@192.168.9.105);
if(m_pDb2Connect->connected)
{
//insert(); // insert records into table
//select(); // select records from table
printf("conne success");
}
else
{
printf("conne failed");
}
}
catch(db2::otl_exception& p)
{
// intercept OTL exceptions
cout<<"connect error"<cerr<cerr<cerr<cerr<}
m_pDb2Connect->logoff(); // disconnect from DB2-CLI
return 0;
}
跪求高手指教,非常感谢!!