[转帖]ORA-12154: TNS 原理及故障分析_MySQL, Oracle及数据库讨论区_Weblogic技术|Tuxedo技术|中间件技术|Oracle论坛|JAVA论坛|Linux/Unix技术|hadoop论坛_联动北方技术论坛  
网站首页 | 关于我们 | 服务中心 | 经验交流 | 公司荣誉 | 成功案例 | 合作伙伴 | 联系我们 |
联动北方-国内领先的云技术服务提供商
»  游客             当前位置:  论坛首页 »  自由讨论区 »  MySQL, Oracle及数据库讨论区 »
总帖数
2
每页帖数
101/1页1
返回列表
0
发起投票  发起投票 发新帖子
查看: 2512 | 回复: 1   主题: [转帖]ORA-12154: TNS 原理及故障分析        上一篇   下一篇 
7758
注册用户
等级:列兵
经验:83
发帖:1
精华:0
注册:2017-3-28
状态:离线
发送短消息息给7758 加好友    发送短消息息给7758 发消息
发表于: IP:您无权察看 2019-9-16 16:43:23 | [全部帖] [楼主帖] 楼主

     总结一下,装了解决Oracle Developer Tools之后,出现“ORA-12154: TNS: 无法解析指定的连接标识符”报错的解决方法如下:    1.检查注册表,HKey_LocalMachineSoftwareOracle下面的Oracle_Home,若不对,修改成正确的;    2.卸载ODP for .Net (或者卸载ODT for .Net, ODT中包含ODP, ODT 是VS.Net的一个集成插件,用于连接和浏览oracle数据库,并且提供对oracle数据库的拖拽操作,类似VS.Net对于SQL Server的资源管理器);    3.如果ODT for .Net的目录依然存在,删除或者重命名此目录;    然后重起系统,重新连接ASP.Net程序,如果还有同样的错误,看着办吧,我建议重装Oracle吧。

    分析原因:系统原来装的是ORACLE 10G 10.1.0,卸载后还没重启就装上10.2.0,结果先是监听器起不来,竟然还是指向10.1.0的位置,监听器当然不能启动了。

    处理过程:    1、查找注册表,将监听器指向新的位置,重启服务,OK;    2、PL/SQL DEVELOPER还是连接不了,其它方式都正常。将原先安装在其它逻辑盘的ODP for .Net 卸载重装到与ORACLE 10.2.0同一位置。重启系统,DEVELOPER还是报错,不过些时报错提示信息为空。    3、因为DEVELOPER设置有更改后,进入菜单TOOLS》PREFERENCES...设置,在ORACLE下的CONNECTION中,将ORACLE HOME和OCI LIBIARY设为空即自动检测。连接正常,问题解决。

    二、应用程序中报错:

    一个很难想到的引起ORA-12154的原因        使用OracleClient.OracleConnection时(我连的是Oracle 9i,其他版本未知),如果你的执行目录太长或者有括号等(未考察有些什么符号),那么即使你的服务名是对的,也会引起ORA-12154问题“TNS: 无法处理服务名”,当出现这个问题时,请也考虑这个原因。

B.进行适当的配置如何正确配置tnsname.ora文件:可以在客户端机器上使用oracle Net Configuration Assistant或oracle Net Manager图形配置工具对客户端进行配置,该配置工具实际上修改tnsnames.ora文件。所以我们可以直接修改tnsnames.ora文件,下面以直接修改tnsnames.ora文件为例:该文件的位置为: …networkadmintnsnames.ora (for windows)…/network/admin/tnsnames.ora (for unix)此处,假设服务器名为testserver,服务名为orcl.testserver.com,使用的侦听端口为1521,则tnsnams.ora文件中的一个test网络服务名(数据库别名)为:test =(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=testserver)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=orcl.testserver.com)))此处的笑脸为)。  红色的内容为需要根据实际情况修改的内容,现解释如下:    PROTOCOL:客户端与服务器端通讯的协议,一般为TCP,该内容一般不用改。    HOST:数据库侦听所在的机器的机器名或IP地址,数据库侦听一般与数据库在同一个机器上,所以当我说数据库侦听所在的机器一般也是指数据库所在的机 器。在UNIX或WINDOWS下,可以通过在数据库侦听所在的机器的命令提示符下使用hostname命令得到机器名,或通过ipconfig(for WINDOWS) or ifconfig(for UNIX)命令得到IP地址。需要注意的是,不管用机器名或IP地址,在客户端一定要用ping命令ping通数据库侦听所在的机器的机器名,否则需要在 hosts文件中加入数据库侦听所在的机器的机器名的解析。    PORT:数据库侦听正在侦听的端口,可以察看服务器端的listener.ora文件或在数据库侦听所在的机器的命令提示符下通过lnsrctl status [listener name]命令察看。此处Port的值一定要与数据库侦听正在侦听的端口一样。    SERVICE_NAME:在服务器端,用system用户登陆后,sqlplus> show parameter service_name命令察看。

  如何利用配置的网络服务名连接到数据库:    用sqlplus程序通过test网络服务名进行测试,如sqlplus system/manager@test。如果不能连接到数据库,则在tnsname.ora文件中的test网络服务名(net service)后面加上sqlnet.ora文件中NAMES.DEFAULT_DOMAIN参数的值,此处我的参数值为testserver.com,将其加到网络服务名后面,修改后的tnsname.ora中关于该网络服务名的内容为:

  什么情况下会引起oracle自动设置NAMES.DEFAULT_DOMAIN参数?    出现这种情况的典型环境为windows的客户端的‘我得电脑à属性à计算机名à更改à其它…à此计算机的主DNS后缀’中设置了‘primary dns suffix’,因为在这种情况下安装客户端时,会在sqlnet.ora文件中自动设置NAMES.DEFAULT_DOMAIN参数,或许当把计算机加入域中安装oracle客户端时也会出现这种情况,有条件的话大家可以试一下。

  我在设置oracle的客户端时一般手工修改tnsnames.ora文件,但是还有许多人喜欢用图形工具配置,该图形工具最终还是修改tnsnames.ora文件,但是它有时会引起其它的问题:    在用oracle的图形配置软件'net assistant'或‘Net Configuration Assistant’配置网络服务名时,假如已经设置了‘primary dns suffix’,但是在图形配置软件中写的网络服务名的名字中没有‘primary dns suffix’,如只是写了test,则图形配置软件会自动在后面加上‘primary dns suffix’,使之变为test.testserver.com,并存在tnsnames.ora中,而不管你的sqlnet.ora文件中是否有 NAMES.DEFAULT_DOMAIN参数。此时,用图形工具进行测试连接是通过的,但是假如此时sqlnet.ora文件中没有 NAMES.DEFAULT_DOMAIN参数,则你在使用网络服务名时应该使用在tnsnames.ora中的 test.testserver.com,而不是你在图形配置软件中键入的test。解决的办法为:<1>可以在sqlnet.ora文件中设置NAMES.DEFAULT_DOMAIN= testserver.com,这时你可以用test或test.testserver.com连接数据库<2>在sqlnet.ora文件中不设置NAMES.DEFAULT_DOMAIN参数,在tnsnames.ora文件中将test.testserver.com中的.testserver.com去掉,这时你可以用test连接数据库。

    关于为什们在网络服务名后面加db_domain参数,需要了解sql*plus连接数据库的原理,我在后面解决12154常见故障中给出了详细的说明。

如果上面的招数还不奏效的话,只好用一下乾坤大挪移了。将客户端的网络服务名部分test.testserver.com =(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=testserver)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=orcl.testserver.com)))此处的笑脸为)。拷贝到服务器的tnsnames.ora文件中。然后再服务器端用sqlplus system/manager@test.testserver.com连接到数据库。    如果能连接成功,说明你的客户端与服务器端的网络有问题。    如果连接不成功,用前面的部分检查网络服务名部分部分是否正确,如果确信网络服务名部分正确而且所有的客户端都连不上数据库则可能为系统TCP/IP或Oracle系统有问题,建议重新安装数据库。

常见故障解决办法:TNS-12154 (ORA-12154):TNS:could not resolve service name该错误表示用于连接的网络服务名在tnsnames.ora文件中不存在,如上面的tnsnames.ora中的网络服务名只有test,假如用户在连接时用sqlplus system/manager@test1则就会给出TNS-12154错误。要注意的是,有时即使在tnsnames.ora文件中有相应的网络服务名,可是用该网络服务名连接时还会出错,出现这种情况的典型配置如下(在客户端的机器上):sqlnet.ora文件:NAMES.DIRECTORY_PATH = (TNSNAMES, ….)NAMES.DEFAULT_DOMAIN = server.comtnsnames.ora文件:test =(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=testserver)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=orcl.testserver.com)))此处的笑脸为)。

  sql*plus运行基本机理:    在用户输入sqlplus system/manager@test后,sqlplus程序会自动到sqlnet.ora文件中找NAMES.DEFAULT_DOMAIN参数,假 如该参数存在,则将该参数中的值取出,加到网络服务名的后面,即此例中你的输入由sqlplus system/manager@test自动变为sqlplus system/manager@test.server.com ,然后再到tnsnames.ora文件中找test.server.com网络服务名,这当然找不到了,因为该文件中只有test网络服务名,所以报 错。解决的办法就是将sqlnet.ora文件中的NAMES.DEFAULT_DOMAIN参数注释掉即可,如 #NAMES.DEFAULT_DOMAIN = server.com。假如NAMES.DEFAULT_DOMAIN参数不存在,则sqlplus程序会直接到tnsnames.ora文件中找 test网络服务名,然后取出其中的host,port,tcp,service_name,利用这些信息将连接请求发送到正确的数据库服务器上。    另外原则上tnsnames.ora中的配置不区分大小写,但是我的确遇到区分大小写的情况,所以最好将使用的网络服务与tnsnames.ora中配置的完全一样。

ORA-12514: TNS:listener could not resolve SERVICE_NAME given in connect Descriptor.该错误表示能在tnsnames.ora中找到网络服务名,但是在tnsnames.ora中指定的SERVICE_NAME与服务器端的SERVICE_NAME不一致。解决的办法是修改tnsnames.ora中的SERVICE_NAME。

  易混淆术语介绍:    Db_name:对一个数据库(Oracle database)的唯一标识,该数据库为第一章讲到的Oracle database。这种表示对于单个数据库是足够的,但是随着由多个数据库构成的分布式数据库的普及,这种命令数据库的方法给数据库的管理造成一定的负 担,因为各个数据库的名字可能一样,造成管理上的混乱。为了解决这种情况,引入了Db_domain参数,这样在数据库的标识是由Db_name和 Db_domain两个参数共同决定的,避免了因为数据库重名而造成管理上的混乱。这类似于互连网上的机器名的管理。我们将Db_name和 Db_domain两个参数用’.’连接起来,表示一个数据库,并将该数据库的名称称为Global_name,即它扩展了Db_name。 Db_name参数只能由字母、数字、’_’、’#’、’\$’组成,而且最多8个字符。

    Db_domain:定义一个数据库所在的域,该域的命名同互联网的’域’没有任何关系,只是数据库管理员为了更好的管理分布式数据库而根据实际情况决定的。当然为了管理方便,可以将其等于互联网的域。

    Global_name:对一个数据库(Oracle database)的唯一标识,oracle建议用此种方法命令数据库。该值是在创建数据库是决定的,缺省值为Db_name. Db_domain。在以后对参数文件中Db_name与Db_domain参数的任何修改不影响Global_name的值,如果要修改Global_name,只能用ALTER DATABASE RENAME GLOBAL_NAME TO <db_name.db_domain>命令进行修改,然后修改相应参数。

    Service_name:该参数是oracle8i新引进的。在8i以前,我们用SID来表示标识数据库的一个实例,但是在Oracle的并行环境中, 一个数据库对应多个实例,这样就需要多个网络服务名,设置繁琐。为了方便并行环境中的设置,引进了Service_name参数,该参数对应一个数据库, 而不是一个实例,而且该参数有许多其它的好处。该参数的缺省值为Db_name. Db_domain,即等于Global_name。一个数据库可以对应多个Service_name,以便实现更灵活的配置。该参数与SID没有直接关 系,即不必Service name 必须与SID一样。

    Net service name:网络服务名,又可以称为数据库别名(database alias)。是客户端程序访问数据库时所需要,屏蔽了客户端如何连接到服务器端的细节,实现了数据库的位置透明的特性。




赞(0)    操作        顶端 
联动大白
注册用户
等级:列兵
经验:91
发帖:0
精华:0
注册:2015-5-27
状态:离线
发送短消息息给联动大白 加好友    发送短消息息给联动大白 发消息
发表于: IP:您无权察看 2019-10-19 0:30:00 | [全部帖] [楼主帖] 2  楼

为了方便大家阅读,我对文章中错误号来解释一下吧!

Error Id: ORA-12154

Title: TNS:could not resolve the connect identifier specified

Description:

TNS:could not resolve the connect identifier specified

Action:

- If you are using local naming (TNSNAMES.ORA file): - Make sure that "TNSNAMES" is listed as one of the values of the NAMES.DIRECTORY_PATH parameter in the Oracle Net profile (SQLNET.ORA) - Verify that a TNSNAMES.ORA file exists and is in the proper directory and is accessible. - Check that the net service name used as the connect identifier exists in the TNSNAMES.ORA file. - Make sure there are no syntax errors anywhere in the TNSNAMES.ORA file. Look for unmatched parentheses or stray characters. Errors in a TNSNAMES.ORA file may make it unusable. - If you are using directory naming: - Verify that "LDAP" is listed as one of the values of the NAMES.DIRETORY_PATH parameter in the Oracle Net profile (SQLNET.ORA). - Verify that the LDAP directory server is up and that it is accessible. - Verify that the net service name or database name used as the connect identifier is configured in the directory. - Verify that the default context being used is correct by specifying a fully qualified net service name or a full LDAP DN as the connect identifier - If you are using easy connect naming: - Verify that "EZCONNECT" is listed as one of the values of the NAMES.DIRETORY_PATH parameter in the Oracle Net profile (SQLNET.ORA). - Make sure the host, port and service name specified are correct. - Try enclosing the connect identifier in quote marks. See the Oracle Net Services Administrators Guide or the Oracle operating system specific guide for more information on naming.

Cause:

A connection to a database or other service was requested using a connect identifier, and the connect identifier specified could not be resolved into a connect descriptor using one of the naming methods configured. For example, if the type of connect identifier used was a net service name then the net service name could not be found in a naming method repository, or the repository could not be located or reached.


Error Id: ORA-12514

Title: TNS:listener does not currently know of service requested in connect descriptor

Description:

TNS:listener does not currently know of service requested in connect descriptor

Action:

- Wait a moment and try to connect a second time. - Check which services are currently known by the listener by executing: lsnrctl services <listener name> - Check that the SERVICE_NAME parameter in the connect descriptor of the net service name used specifies a service known by the listener. - If an easy connect naming connect identifier was used, check that the service name specified is a service known by the listener. - Check for an event in the listener.log file.

Cause:

The listener received a request to establish a connection to a database or other service. The connect descriptor received by the listener specified a service name for a service (usually a database service) that either has not yet dynamically registered with the listener or has not been statically configured for the listener. This may be a temporary condition such as after the listener has started, but before the database instance has registered with the listener.


Error Id: TNS-12154

Title: TNS:could not resolve the connect identifier specified

Description:

TNS:could not resolve the connect identifier specified

Action:

- If you are using local naming (TNSNAMES.ORA file): - Make sure that "TNSNAMES" is listed as one of the values of the NAMES.DIRECTORY_PATH parameter in the Oracle Net profile (SQLNET.ORA) - Verify that a TNSNAMES.ORA file exists and is in the proper directory and is accessible. - Check that the net service name used as the connect identifier exists in the TNSNAMES.ORA file. - Make sure there are no syntax errors anywhere in the TNSNAMES.ORA file. Look for unmatched parentheses or stray characters. Errors in a TNSNAMES.ORA file may make it unusable. - If you are using directory naming: - Verify that "LDAP" is listed as one of the values of the NAMES.DIRETORY_PATH parameter in the Oracle Net profile (SQLNET.ORA). - Verify that the LDAP directory server is up and that it is accessible. - Verify that the net service name or database name used as the connect identifier is configured in the directory. - Verify that the default context being used is correct by specifying a fully qualified net service name or a full LDAP DN as the connect identifier - If you are using easy connect naming: - Verify that "EZCONNECT" is listed as one of the values of the NAMES.DIRETORY_PATH parameter in the Oracle Net profile (SQLNET.ORA). - Make sure the host, port and service name specified are correct. - Try enclosing the connect identifier in quote marks. See the Oracle Net Services Administrators Guide or the Oracle operating system specific guide for more information on naming.

Cause:

A connection to a database or other service was requested using a connect identifier, and the connect identifier specified could not be resolved into a connect descriptor using one of the naming methods configured. For example, if the type of connect identifier used was a net service name then the net service name could not be found in a naming method repository, or the repository could not be located or reached.


也许你已明白,但对一个人有用也是我存在的理由!^_^ By:持之以恒的大白

-- 来自: 北京联动北方科技有限公司



赞(0)    操作        顶端 
总帖数
2
每页帖数
101/1页1
返回列表
发新帖子
请输入验证码: 点击刷新验证码
您需要登录后才可以回帖 登录 | 注册
技术讨论