我在 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 orcl
都tnsping 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)