ORA-12154使用TNS别名连接时



我在Win7x64笔记本电脑上安装了Oracle 11.2,几乎所有内容都可以正常工作。但是,我不明白的一件事。我可以通过以下方式连接到示例HR模式。

sqlplus hr/password

,但不使用:

sqlplus hr/password@orcl

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

我偶然发现了这一点,因为我期望第二种选择是正确的。我为什么要忽略TNS别名?我是Oracle初学者,但是当我连接到其他环境时,需要TNS别名或我无法建立连接。

我在tnsnames.ora中有以下内容:

LISTENER_ORCL = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
ORACLR_CONNECTION_DATA = (DESCRIPTION =
  (ADDRESS_LIST = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)))
  (CONNECT_DATA = (SID = CLRExtProc)(PRESENTATION = RO)))
ORCL, DUMMY = (DESCRIPTION =
  (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
  (CONNECT_DATA = (SERVER = DEDICATED)(SERVICE_NAME = orcl)))

我肯定知道它正在使用,因为tnsping orcltnsping dummy都可以。有人可以向我解释吗?

更新1 lsnrctl status的输出为:

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for 64-bit Windows: Version 11.2.0.1.0 - Production
Start Date                11-NOV-2012 00:43:22
Uptime                    0 days 0 hr. 15 min. 53 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   C:appRonaldproduct11.2.0dbhome_1networkadminlistener.ora
Listener Log File         c:appronalddiagtnslsnrRonald-PDClisteneralertlog.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\.pipeEXTPROC1521ipc)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=1521)))
Services Summary...
Service "CLRExtProc" has 1 instance(s).
  Instance "CLRExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "orcl" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orclXDB" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service...
The command completed successfully

SELECT name FROM v$database的结果是一个数据库:ORCL

更新2 tnsping orcl的输出(格式为可读性)。

Used parameter files:
C:appRonaldproduct11.2.0dbhome_1networkadminsqlnet.ora
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION =
  (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
  (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl)))
OK (20 msec)

您是否实际创建了一个名为orcl的数据库实例?

使用命令

查看数据库的实际名称
lsnrctl status

这应该告诉您听众知道哪些服务,这就是您与 @语法联系时所说的服务。无需 @orcl即可连接的原因是,在这种情况下,您正在使用intercocess Communication(ipc)并绕过侦听器,因为数据库与SQL*Plus Client Session在同一计算机上。

在第一个示例中连接以下示例时,您也可以找到数据库名称:

SELECT name FROM v$database;

编辑:

尝试ezconnect语法,看看是否有效:

sqlplus user/pw@localhost/ORCL

请记住,TNSPING除了与侦听器联系以外没有做任何事情 - 它无法验证数据库。

另外一件事:看来TCP可能不是侦听器配置的协议?检查您的Luctiler.ora文件(与您的tnsnames.ora文件相同的目录)。听众的条目应该看起来像这样:

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
  )

我的TNSPING输出在输出开始附近的一行中看起来有些不同:

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=myhost)(PORT=1521)))

相关内容

  • 没有找到相关文章

最新更新