当前位置: 代码迷 >> 综合 >> Oracle-ORA-12545 Connect failed because target host or object does not exist 解决
  详细解决方案

Oracle-ORA-12545 Connect failed because target host or object does not exist 解决

热度:30   发布时间:2024-03-06 19:19:30.0

最近碰到一个古怪的问题,使用TNSNAMES适配器来连接数据库的时候,一样的net servie名,在Windows上连接成功,在Linux上连接失败,搞得挺惨的,原因就是IPv6两头有俩方括号,Windows上要,Linux上不要。

 

在Linux上,使用EZCONNECT适配器的话,是可以连接的,使用过TNSNAMES的话,报标题ORA-12545错误,提示主机无法识别。

 

<EZCONNECT适配器>

tnsping [2001:cf6:0:6d1:3:0:a2a2:1b1b]:1521/SID001

※[2001:cf6:0:6d1:3:0:a2a2:1b1b]是一个假想的IPv6地址

 

返回消息:

TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 21-10月-2020 11:09:28

Copyright (c) 1997, 2013, Oracle.  All rights reserved.

Used parameter files:
/opt/oracle/product/11.2.0/client_1/network/admin/sqlnet.ora

Used EZCONNECT adapter to resolve the alias Attempting to contact
(DESCRIPTION=(CONNECT_DATA=(SERVICE_NAME=SID001))(ADDRESS=(PROTOCOL=TCP)(HOST=2001:cf6:0:6d1:3:0:a2a2:1b1b)(PORT=1521)))
OK (10 msec)

 

<TNSNAMES适配器>

tnsping TEST001

 

返回消息:

TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 21-10月-2020 10:37:11

Copyright (c) 1997, 2013, Oracle.  All rights reserved.

Used parameter files:
/opt/oracle/product/11.2.0/client_1/network/admin/sqlnet.ora


Used TNSNAMES Tadapter to resolve the alias Attempting to contact
(DESCRIPTION = (ADDRESS_LIST= (LOAD_BALANCE=on) (FAILOVER=on) (ADDRESS = (PROTOCOL = TCP)(HOST = [2001:cf6:0:6d1:3:0:a2a2:1b1b])(PORT = 1521))) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = SID001)))
TNS-12545: Connect failed because target host or object does not exist

 

<这是TNSNAMES.ora定义>

TEST001 =
  (DESCRIPTION =
    (ADDRESS_LIST=
      (LOAD_BALANCE=on)
      (FAILOVER=on)
      (ADDRESS = (PROTOCOL = TCP)(HOST = [2001:cf6:0:6d1:3:0:a2a2:1b1b])(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = SID001)
    )
  )

 

 

问题就在这个红字儿的括号上面,Linux上不需要,所以Linux下删掉就可以了。Windows上需要,要加上。

如果你两个操作系统都用的时候,兴许你也会被绊个跟头,希望有帮助!

  相关解决方案