oracle 数据库连接错误:ORA-12154,ORA-12523

起由:在本机启动两个数据库, orcl和HIS, 在服务端连接没有问题。采用客户端模式连接时,在PL/SQL连接数据库时,经常会报以下两个错误。

ORA-12154: TNS:could not resolve the connect identifierspecified

ORA-12523: TNS:listener could not find instance appropriate for the client connection

      在后台,用SQLPlus命令connect 连接,显示CONNECTED。说明服务启动正常,只是PL/SQL连接不上数据库。

       如果关掉一个数据库,只启动一个数据库时,连接就是好的。如果两个数据库启动后,再连接,就会继续报上面的错误,一个也连接不上。

      客户端文件:tnsnames.ora,内容如下:

HIS =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = his)
    )
  )

ORCL =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = ORCL)
    )
  )

将HOST = 127.0.0.1改成HOST = LOCALHOST,如下:

HIS =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = LOCALHOST)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = his)
    )
  )

ORCL =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = LOCALHOST)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = ORCL)
    )
  )

    关闭PL/SQL, 重新再连接,OK,一切正常。

    原来一直认为TCP连接中,127.0.0.1就是LOCALHOST,理解有误,尽管当前浏览器上访问时,127.0.0.1LOCALHOST访问的是同一个地址。

你可能感兴趣的:(oracle,数据库,连接)