简体   繁体   English

带有 C++ 的 OCCI 错误:TNS:net 服务名称指定错误

[英]OCCI with C++ error: TNS:net service name is incorrectly specified

I have created a simple C++ programm to connect the Oracle OCCI with a OracleDB instance.我创建了一个简单的 C++ 程序来将 Oracle OCCI 与 OracleDB 实例连接起来。

Here is the Code:这是代码:

#include <iostream>
#include <string>
#include <occi.h>

//  Connection information
const std::string userName = "admin";
const std::string password = "password";

const std::string connectString = "(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.8.190)(PORT = 1521)))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = ORCLCDB)))";                    

//  Connection enviroment
oracle::occi::Environment *env = oracle::occi::Environment::createEnvironment();


int main() {

int succes;

oracle::occi::Connection *conn = env->createConnection(userName, password, connectString);
succes = 0;

std::string id;
std::cin >> id;

std::string anw = "SELECT * FROM BESTAND WHERE ID=";

std::string cnw = anw + id;

oracle::occi::Statement *stmt = conn -> createStatement(cnw);

oracle::occi::ResultSet *rs = stmt -> executeQuery();

while (rs -> next()) {

std::string b = rs -> getString(2);

std::cout << b << std::endl;

}



stmt -> closeResultSet(rs);
conn -> terminateStatement(stmt);
env -> terminateConnection(conn);

oracle::occi::Environment::terminateEnvironment(env);

}

I use g++ on CentOS-8 to complie the programm, and the programm compilies without a problem but when i execute the Programm i get this error:我在 CentOS-8 上使用 g++ 来编译程序,程序编译没有问题,但是当我执行程序时,我得到这个错误:

terminate called after throwing an instance of 'oracle::occi::SQLException'
what():  ORA-12162: TNS:net service name is incorrectly specified

Have anybody here an idea how i can fix this problem.有没有人知道我如何解决这个问题。

Is "ORCLCDB" the SERVICE_NAME, or the ORACLE_SID? “ORCLLCDB”是 SERVICE_NAME 还是 ORACLE_SID? Service names are usually fully qualified with a domain.服务名称通常由域完全限定。 You can try this (spaces are fine):你可以试试这个(空格很好):

(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.8.190)(PORT = 1521))(CONNECT_DATA = (SERVER = DEDICATED)(SID = ORCLCDB)))

Or double-check the service name from the TNS Listener status to make sure you've got the right value.或者从 TNS 侦听器状态仔细检查服务名称,以确保您获得了正确的值。 The "lsnrctl status" command on the database server should return a list of active services;数据库服务器上的“lsnrctl status”命令应该返回一个活动服务列表; use one with a status of "READY".使用状态为“READY”的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM