关于PL/SQL Developer 登陆报错 ora-12154 ORA-12560

来源:互联网 发布:淘宝乐町商城 编辑:程序博客网 时间:2024/06/08 02:18

昨天一同事反映在使用Oracle9i时,在Net Assistant里配置服务名测试通过,但在使用SQL*PLUS等客户端工具时老是连接不上。

·首先检查服务名是否存在,发现服务名的确存在而且在Net Assistant中确实可以连接并测试通过。

·接下来用SQL*PLUS连接报错,错误显示:ORA-12154: TNS:could not resolve service name

·使用Oracle的tnsping命令测试报错,错误显示:TNS-03505: 未能分解名称

本人百思不得其解,只能上网google,多番查找之后终于找到了一篇文章,发现里面的情况和我的一摸一样。现摘录如下:

(尊重原创:作者博客地址为:http://blog.chinaunix.net/u1/44757/index.html)

以下内容为转载部分:
----------------------------------------------------------------------------------------------------------------------------------------
ORA-12154: TNS:could not resolve service name

错误指出客户不能查找到tnsnames.ora文件中所列举的服务。

查错误码显示:

ORA-12154: TNS:could not resolve service name
Cause: Oracle Net could not locate the net service name specified in the tnsnames.ora configuration file.

Action: Perform these steps:
1.Verify that a tnsnames.ora file exists.(See Also: "Localized Configuration File Support" for configuration file location information) 

2.Verify that there are not multiple copies of the tnsnames.ora file. 

3.In the tnsnames.ora file, verify that the net service name specified in your connect string is mapped to a connect descriptor. 

4.Verify that there are no duplicate copies of the sqlnet.ora file. 

5.If you are using domain names, verify that your sqlnet.ora file contains a NAMES.DEFAULT_DOMAIN parameter. If this parameter does not exist, you must specify the domain name in your connect string. 

6.If you are not using domain names, and this parameter exists, delete it or disable it by commenting it out.

7.If you are connecting from a login dialog box, verify that you are not placing an "@" symbol before your connect net service name. 

8.Activate client tracing and repeat the operation. 

 

Cause: Oracle Net could not locate the database service name or net service name specified in the directory server.

Action: Perform these steps:
1.Verify that the database service or net service name entry exists in the directory that this computer was configured to use. 
  (See Also: Chapter 8, "Setting Up Directory Server Usage" for directory setup instructions) 

2.Verify that the sqlnet.ora file includes the following entry: NAMES.DIRECTORY_PATH=(ldap, other_naming_methods)
  根据文档中的提示第三步3.(1.2没问题了)检查tnsnames.ora文件中的服务名称是否正确的配置,经过检查(SERVICE_NAME = hatest)没有问题
  然后按照文档做第4.5步,到第6步时发现问题,sqlnet.ora文件中引用了domain域(注:我们这边没使用域)
  [oracle@localhost admin]$ cat sqlnet.ora
  # SQLNET.ORA Network Configuration File: /home/oracle/OraHome1/network/admin/sqlnet.ora
  # Generated by Oracle configuration tools.
  NAMES.DEFAULT_DOMAIN = localdomain
  NAMES.DIRECTORY_PATH= (TNSNAMES, ONAMES, HOSTNAME)--这个没问题啦

  好了那还等什么编辑该文件把domain干掉。编辑完后赶快tnsping hatest
  [oracle@localhost admin]$ tnsping hatest
  TNS Ping Utility for Linux: Version 9.2.0.4.0 - Production on 26-APR-2007 16:33:39
  Copyright (c) 1997 Oracle Corporation.  All rights reserved.
  Used parameter files:
  /home/oracle/OraHome1/network/admin/sqlnet.ora
  Used TNSNAMES adapter to resolve the alias
  Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST =   
  192.168.248.155)(PORT = 1521))) (CONNECT_DATA = (SID = hatest) (SERVER = DEDICATED)))
  OK (30 msec)

  没问题通了。再连接数据库

  [oracle@localhost admin]$ sqlplus hangan/hangan@hatest
  SQL*Plus: Release 9.2.0.4.0 - Production on Thu Apr 26 16:33:49 2007
  Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.
  Connected to:
  Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
  With the Partitioning, OLAP and Oracle Data Mining options
  JServer Release 9.2.0.4.0 - Production
  
  SQL> exit
----------------------------------------------------------------------------------------------------------------------------------------

看了上面的描述之后,我按照步骤一步步检查,到了检查sqlnet.ora文件的时候,问题就出来了。原来这位同事的sqlnet.ora文件中是这样的:

# SQLNET.ORA Network Configuration File: C:/oracle/ora81/network/admin/sqlnet.ora
# Generated by Oracle configuration tools.

NAMES.DEFAULT_DOMAIN = eapac.ericsson.se

SQLNET.AUTHENTICATION_SERVICES= (NTS)

NAMES.DIRECTORY_PATH= (ONAMES)

可以看到这里只使用了ONAMES来查找服务,但他的服务是配置在tnsnames.ora文件中,当在SQL*PLUS中连接时,Oracle不是按tnsname的方式来查找,当然找不到服务了。

问题找到了,将NAMES.DIRECTORY_PATH 改为:
NAMES.DIRECTORY_PATH= (TNSNAMES, HOSTNAME, ONAMES)

再测试连接通过,问题解决。

在此要感谢博文的博主,也感觉文中的DBA解决问题的思路很清晰,看来自己离一个合格的DBA还有很长的距离,继续努力中。

 

 

附:

 

安装好oracle10客户端,配置好网络服务名称,用enterprsie manager console 连接服务器,一切正常,连接成功。

 

接着安装plsql developer,安装完成后,运行plsql, 输入用户名和密码,数据库名称输入刚才配置的服务名称,点击登录,出现ora-12154错误。 随即上网搜索,查找资料。按照网上说的试了试,虽然没成功,大概知道了问题出在哪。

 

因为用manager console 能登录,plsql不能登录,说明网络服务名配置的没有问题,问题可能出在plsql不能找到网络服务名的配置文件,即找不到C:/oracle/product/10.2.0/client_1/NETWORK/ADMIN/tnsnames.ora。看了看系统环境变量,发现ORACLE_HOME的值为空,试着设置为ORACLE_HOME=c:/oracle/product/10.2.0/client_1。重新登录plsql,登录上去了。

 

没想到是ORACLE_HOME惹得祸!

 

总结:

 

碰到ora-12154错误,首先确认自己输入的服务名是不是正确,服务名不区分大小写。 然后,看看系统的环境变量中

ORACLE_HOME的值是不是正确,ORACLE_HOME的值要设置到client目录。

 

ORA-12560:

四种情况:

1.监听服务没有起起来。windows平台个一如下操作:开始---程序---管理工具---服务,打开服务面板,启动oraclehome92TNSlistener服务。

2.database instance没有起起来。windows平台如下操作:开始---程序---管理工具---服务,打开服务面板,启动oracleserviceXXXX,XXXX就是你的database SID.

3.注册表问题。regedit,然后进入HKEY_LOCAL_MACHINE/SOFTWARE/ORACLE/HOME0将该环境变量ORACLE_SID设置为XXXX,XXXX就是你的database SID.或者右几我的电脑,属性--高级--环境变量---系统变量--新建,变量名=oracle_sid,变量值=XXXX,XXXX就是你的database SID.或者进入sqlplus前,在command line下输set oracle_sid=XXXX,XXXX就是你的database SID.

4.修改PL/SQL Developer---Tools---Preferences---Oracle Home(要与

HKEY_LOCAL_MACHINE/SOFTWARE/ORACLE/下的键值一直且去掉“KEY-”

)---OCI library---设置争取如:E:/oracle/product/10.2.0/db_1/bin/oci.dll。

 

经过以上步骤,就可以解决问题。