【求助】使用occi连接数据库时出错:ORA-12537:TNS:connection closed
只不过是:刚在新装的Centos下安装了oracle11g。在sqlplus下使用select table_name from user_tables,能够成功执行并返回结果,说明数据库已经正常运行了。
现在想要通过写一个occi连接oracle的小程序在本机测验一下是否能够正常操作oracle数据库。代码极其简单:
#include <iostream>
#include <occi.h>
#include <sstream>
#include <time.h>
using namespace std;
using namespace oracle::occi;
int main()
{
Environment *env = Environment::createEnvironment(Environment::DEFAULT);
string name = "sys";
string pass = "123";
string srvName = "xxx.xxx.xxx.xxx:1521/ORCL"; //ip是本机的ip地址。
cout << " run to 1 !!!!!!!!" << endl;
Connection *conn = env->createConnection(name,pass,srvName);
cout << " run to 2 !!!!!!!!" << endl;
if(conn) cout << "con suc" << endl;
Statement *stmt = NULL;
string sql = "select table_name from user_tables where rownum<=5";
stmt = conn->createStatement();
stmt->setSQL(sql);
ResultSet *rs = NULL;
rs = stmt->executeQuery();
while(rs->next())
{
cout << "name: " << rs->getString(1) << endl;
}
return 0;
}
编译通过后,先sqlplus>startup,后lsnrctl start。
运行程序,出现错误:ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
出现此问题后,查询解决方法,在listener.ora文件中加入:
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = ORCL.LOCAL)
(ORACLE_HOME = /opt/oracle/11g)
(SID_NAME = ORCL)
)
)
先关闭后重启数据库服务和监听。再次运行程序又出现错误:ORA-12537: TNS:connection closed
使用lsnrctl status查看监听状态显示如下:
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 21-FEB-2014 18:50:56
Copyright (c) 1991, 2009, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date 21-FEB-2014 18:01:47
Uptime 0 days 0 hr. 49 min. 9 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /opt/oracle/11g/network/admin/listener.ora
Listener Log File /opt/oracle/diag/tnslsnr/ma/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=222.201.139.194)(PORT=1521))(PROTOCOL_STACK=(PRESENTATION=GIOP)(SESSION=RAW)))
Services Summary...
Service "ORCL.LOCAL" has 1 instance(s).
Instance "ORCL", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
状态是unknown是否不对啊,是不是应该是ready才对呢?
此问题,在网上查了好多资料还是不知道如何解决,网上有说是限制ip的问题,在我的配置里边没有限制。
我只是想使用occi编程操作数据库,数据库现在应该是正常运行了,可能是网络连接配置的问题,现在连接不上数据。
现在真的迷茫了,大家帮帮忙,这是怎么回事。
相关推荐
用Navicat连接Oracle数据库时报错ORA-28547:connection to server failed,probable Oracle Net admin error-附件资源
用Navicat连接Oracle数据库时报错ORA-28547:connection to server failed,probable Oracle Net admin error-附件资源
TNS-12547: TNS:lost contact TNS-12537: TNS:connection closed as a result of ORA-609
检查alert日志发现如下报错: Tue Nov 17 01:04:49 2015 *********************************************************************** Fatal NI connect error 12547, connecting to: (LOCAL=NO) VERSION INFORMATION:
ORA-12154_TNS无法解析指定的连接标识符
ORA-12154_TNS无法解析指定的连接标识符
oracle数据库tns配置方法详解
TNS简要介绍与应用 Oracle中TNS的完整定义:transparence Network Substrate透明网络底层,监听服务是它重要的一部分,不是全部,不要把TNS当作只是监听器。 TNS是Oracle Net的一部分,专门用来管理和配置Oracle数据库和客户端连接的一个工具,在大多数情况下客户端和数据库要通讯,必须配置TNS,当然在少数情况下,不用配置TNS也可以连接Oracle数据库,比如通过JDBC。如果通过TNS连接Oracle,那么客户端必须安装Oracle client程序。 Oracle当中,如果想访问某个服务器,必须要设置TNS,它不像SQL SERVER那样在客
Oracle_ORA-12518故障_处理
Oracle_ORA-12518故障_处理,希望在此与大家分享,能够在实际的工作中提高解决问题的能力


