我正在尝试连接到远程服务器上的 oracle DB:
userid = getenv("ORACLE_USER");
oracle_password = getenv("ORACLE_USER_PASSWORD");
db_name = getenv("DB_NAME");
EXEC SQL CONNECT :userid IDENTIFIED BY :oracle_password USING :db_name;
我收到一个错误:ORA-01034。
我很乐意寻求帮助。谢谢。
EXEC SQL BEGIN DECLARE SECTION;
userid VARCHAR(50);
oracle_password VARCHAR(50);
db_name VARCHAR(50);
EXEC SQL END DECLARE SECTION;
main()
{
userid.arr = getenv("ORACLE_USER");
userid.len = strlen(userid.arr);
oracle_password.arr = getenv("ORACLE_USER_PASSWORD");
oracle_password.len = strlen(oracle_password.arr);
db_name.arr = getenv("DB_NAME");
db_name.len = strlen(db_name.arr);
EXEC SQL CONNECT :userid IDENTIFIED BY :oracle_password USING :db_name;
if (sqlca.sqlcode==0)
{
prnitf("sucessful");
}
else
{
printf("failed");
return;
}
}
希望它对你有用。
首先,使用替代格式:EXEC SQL CONNECT :usr_pwd; 其中主机变量 usr_pwd 包含您的用户名和密码,由斜杠字符 (/) 分隔。
然后对于 usr_pwd 附加远程服务器信息:“user/pwd@(DESCRIPTION = (ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = xx.xx.xx.xx)(PORT = xxxx)))(CONNECT_DATA = (SERVICE_NAME = xxxxx)))"
为了快速验证,您可以使用 sqlplus 查看它是否先连接,然后插入您的代码并编译: sqlplus user/pwd@(DESCRIPTION = (ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = xx.xx.xx. xx)(PORT = xxxx)))(CONNECT_DATA = (SERVICE_NAME = xxxxx)))