3

我在 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:\app\Ronald\product\11.2.0\dbhome_1\network\admin\listener.ora
Listener Log File         c:\app\ronald\diag\tnslsnr\Ronald-PDC\listener\alert\log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC1521ipc)))
  (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:\app\Ronald\product\11.2.0\dbhome_1\network\admin\sqlnet.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)
4

1 回答 1

2

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

使用命令检查数据库的实际名称

lsnrctl status

这应该告诉您侦听器知道哪些服务,这就是您在使用 @ 语法连接时正在与之交谈的内容。您可以在没有@ORCL 的情况下进行连接的原因是,在这种情况下,您正在使用进程间通信 (IPC) 并绕过侦听器,因为数据库与 SQL*Plus 客户端会话位于同一台计算机上。

您还可以在第一个示例中使用以下方法连接时找出数据库名称:

SELECT name FROM v$database;

编辑:

试试 EZConnect 语法,看看是否可行:

sqlplus user/pw@localhost/ORCL

请记住,TNSPING除了联系侦听器之外不会做任何事情 - 它不会验证可以访问数据库。

还有一件事:看起来 TCP 可能不是为侦听器配置的协议?检查您的 listener.ora 文件(与 tnsnames.ora 文件位于同一目录中)。LISTENER 的条目应如下所示:

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)))
于 2012-11-10T20:18:16.937 回答