tnsnames配置缺少空格导致的ORA-12154

来源:互联网 发布:配煤软件 编辑:程序博客网 时间:2024/06/05 20:46

今天一位网友找我说用sqlplus远程连接总是报错,连接不上,最终检查发现是他本机的tnsnames文件配置格式不对导致的

以下是我模拟的环境,如下:

[oracle@localhost admin]$ sqlplus scott/tiger@goolen
SQL*Plus: Release 11.2.0.1.0 Production on Thu Dec 26 20:23:45 2013
Copyright (c) 1982, 2009, Oracle.  All rights reserved.
ERROR:

ORA-12154: TNS:could not resolve the connect identifier specified


[oracle@localhost admin]$ tnsping goolen
TNS Ping Utility for Linux: Version 11.2.0.1.0 - Production on 26-DEC-2013 20:27:55
Copyright (c) 1997, 2009, Oracle.  All rights reserved.
Used parameter files:

Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.50)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = goolen)
TNS-12533: TNS:illegal ADDRESS parameters


++++telnet 1521端口没有问题
[oracle@localhost admin]$ telnet 192.168.100.50 1521
Trying 192.168.100.50...
Connected to 192.168.100.50 (192.168.100.50).
Escape character is '^]'.
q
quit
Connection closed by foreign host.


++++我突然想起来很早以前看过一片文章,说过这个文件的格式配置不对会导致连接失败,但是记不太清楚了,我想他的应该也是这个问题

然后我在本地自己测试后发现确实如此,如果SERVICE_NAME下的一行缺少空格,就会导致相同的错误

然后让他检查他的tnsnames文件,果然如此,他说是在网上随便贴的格式


+++查看tnsnames文件内容:

[oracle@localhost admin]$ cat tnsnames.ora          
goolen =
(DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.50)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = goolen)
)
)

oracle@localhost admin]$ sqlplus scott/tiger@goolen
SQL*Pls: Release 11.2.0.1.0 Production on Thu Dec 26 20:23:45 2013

Copyright (c) 1982, 2009, Oracle.  All rights reserved.
ERROR:
ORA-12154: TNS:could not resolve the connect identifier specified

+++然后让他把格式改过来,在前面加个空格,然后再次连接,就ok了

[oracle@localhost admin]$ cat tnsnames.ora 
goolen =
(DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.50)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = goolen)
        )
)
[oracle@localhost admin]$ sqlplus scott/tiger@goolen

SQL*Plus: Release 11.2.0.1.0 Production on Thu Dec 26 20:41:40 2013

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> 
SQL> 


0 0
原创粉丝点击