linux下连接oracle数据库出错:ORA-12514 cannot...

今天连接数据库时出了错,监听启动正常,/ 下启动数据库也正常,用sys连接时提示出错,

数据库名是oradb,sid是oradb:

$lsnrctl start

提示:成功!

$sqlplus "/ as sysdba"

sql>startup

提示:成功!

sql>conn sys/oracle@oradb as sysdba;

报错:

ORA-12514: TNS:listener could not resolve SERVICE_NAME given in connect 

descriptor!

我是这样解决的:以root身份登录,查看/oracle/product/9.2.0.4/network/admin目录

下的

listener.ora和tnsnames.ora两个配置文件的配置是否正确。

$vi tnsnames.ora

oradb =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.101)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl.oradb.localdomain)
)
)
修改SERVICE_NAME = orcl.oradb.localdomain为SERVICE_NAME = oradb

保存退出

$vi listener.ora

LISTENER = 
(DESCRIPTION_LIST = 
(DESCRIPTION = 
(ADDRESS_LIST = 
(ADDRESS =(PROTOCOL=TCP)(HOST=192.168.0.101)(PORT= 1521)) 

(ADDRESS_LIST = 
(ADDRESS =(PROTOCOL=IPC)(KEY=EXTPROC))
)

)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /opt/u01/app/oracle/product/9.2.0.4)
(PROGRAM = extproc)
)
)
在SID_LIST_LISTENER 中增加下列内容:
(SID_DESC =
(GLOBAL_DBNAME = oradb)
(ORACLE_HOME = /opt/u01/app/oracle/product/9.2.0.4)
(SID_NAME = oradb)
)

完整的listener.ora的内容是:

LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
)
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.101)(PORT = 1521))
)
)
)

SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /opt/u01/app/oracle/product/9.2.0.4)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = oradb)
(ORACLE_HOME = /opt/u01/app/oracle/product/9.2.0.4)
(SID_NAME = oradb)
)
)

再以oracle身份登录,启动监听和数据库,连接数据库都正常了。

你可能感兴趣的:(linux下连接oracle数据库出错:ORA-12514 cannot...)