当前位置: 技术问答>linux和unix
Pro*C连接问题
来源: 互联网 发布时间:2016-04-21
本文导语: include #include #include EXEC SQL DECLARE dblinkname1 DATABASE; EXEC SQL INCLUDE SQLCA; int main() { EXEC SQL BEGIN DECLARE SECTION; VARCHAR username[50],password[20],dbname[20]; EXEC SQL END DECLARE SECTION; strcpy((...
include
#include
#include
EXEC SQL DECLARE dblinkname1 DATABASE;
EXEC SQL INCLUDE SQLCA;
int main()
{
EXEC SQL BEGIN DECLARE SECTION;
VARCHAR username[50],password[20],dbname[20];
EXEC SQL END DECLARE SECTION;
strcpy((char *)username.arr,"test");
username.len = strlen((char *)username.arr);
strcpy((char *)password.arr,"test");
password.len = strlen((char *)password.arr);
strcpy((char *)dbname.arr,"192.168.3.38"); // tagA 请教此处
dbname.len = strlen((char *)dbname.arr);
EXEC SQL CONNECT :username IDENTIFIED BY :password AT dblinkname1 USING :dbname; // tagB
if (sqlca.sqlcode)
{
printf("fail to connect!n");
return 1;
}
printf("connect to db successfullyn");
EXEC SQL AT dblinkname1 COMMIT WORK RELEASE;
return 0;
}
用Pro*C边本机的Oracle时, tagB处把"using :dbname"去掉就可以了
现在要连接LAN中的另一台机器, IP=92.168.3.38, oracle数据库名=dztl.
请教高手tagA处应该怎么写
#include
#include
EXEC SQL DECLARE dblinkname1 DATABASE;
EXEC SQL INCLUDE SQLCA;
int main()
{
EXEC SQL BEGIN DECLARE SECTION;
VARCHAR username[50],password[20],dbname[20];
EXEC SQL END DECLARE SECTION;
strcpy((char *)username.arr,"test");
username.len = strlen((char *)username.arr);
strcpy((char *)password.arr,"test");
password.len = strlen((char *)password.arr);
strcpy((char *)dbname.arr,"192.168.3.38"); // tagA 请教此处
dbname.len = strlen((char *)dbname.arr);
EXEC SQL CONNECT :username IDENTIFIED BY :password AT dblinkname1 USING :dbname; // tagB
if (sqlca.sqlcode)
{
printf("fail to connect!n");
return 1;
}
printf("connect to db successfullyn");
EXEC SQL AT dblinkname1 COMMIT WORK RELEASE;
return 0;
}
用Pro*C边本机的Oracle时, tagB处把"using :dbname"去掉就可以了
现在要连接LAN中的另一台机器, IP=92.168.3.38, oracle数据库名=dztl.
请教高手tagA处应该怎么写
|
try this:
strcpy((char *)dbname.arr,"dztl@192.168.3.38");
strcpy((char *)dbname.arr,"dztl@192.168.3.38");