【问题标题】:TNSPING OK but sqlplus gives ORA-12154?TNSPING OK 但 sqlplus 给出 ORA-12154?
【发布时间】:2013-11-26 19:48:53
【问题描述】:

我在 Windows 服务器上运行 Oracle 11,我登录到同一台服务器尝试使用 SQL Plus。当我尝试连接时,我得到一个 ORA-12154,即使 TNSPING 和其他各种诊断看起来都不错。

谁能提出原因?下面有很多细节。


如果我像这样使用 EZCONNECT,我可以使用 sqlplus ..

sqlplus EST/EST@192.168.10.15/ORCL

...但是如果我尝试像这样使用 TNSNAMES 进行连接...

sqlplus EST/EST@ORCL

...我明白了...

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

TNSPING工作正常

C:\Documents and Settings\user1>tnsping ORCL

TNS Ping Utility for 64-bit Windows: Version 11.2.0.1.0 - Production on 12-NOV-2013 12:41:14

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

Used parameter files:
E:\app\Administrator\product\11.2.0\dbhome_2\network\admin\sqlnet.ora


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.10.15)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = ORCL))
)
OK (20 msec)

监听器看起来像这样:

C:\Documents and Settings\user1>lsnrctl services

LSNRCTL for 64-bit Windows: Version 11.2.0.1.0 - Production on 14-NOV-2013 12:02:59

Copyright (c) 1991, 2010, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
Services Summary...
Service "CLRExtProc" has 1 instance(s).
  Instance "CLRExtProc", status UNKNOWN, has 1 handler(s) for this service...
    Handler(s):
      "DEDICATED" established:0 refused:0
         LOCAL SERVER
Service "orcl" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service...
    Handler(s):
      "DEDICATED" established:55 refused:0 state:ready
         LOCAL SERVER
Service "orclXDB" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service...
    Handler(s):
      "D000" established:0 refused:0 current:0 max:1022 state:ready
         DISPATCHER <machine: MARIEL, pid: 2400>
         (ADDRESS=(PROTOCOL=tcp)(HOST=mariel)(PORT=1045))
The command completed successfully

还有这个

C:\Documents and Settings\user1>lsnrctl status

LSNRCTL for 64-bit Windows: Version 11.2.0.1.0 - Production on 14-NOV-2013 12:29:21

Copyright (c) 1991, 2010, Oracle.  All rights reserved.

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                14-NOV-2013 11:41:10
Uptime                    0 days 0 hr. 48 min. 11 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   E:\app\Administrator\product\11.2.0\dbhome_2\network\admin\listener.ora
Listener Log File         e:\app\administrator\diag\tnslsnr\mariel\listener\alert\log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC1521ipc)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.10.15)(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

这里是各种配置文件:

listener.ora

# listener.ora Network Configuration File: E:\app\Administrator\product\11.2.0\dbhome_2\network\admin\listener.ora
# Generated by Oracle configuration tools.

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = CLRExtProc)
      (ORACLE_HOME = E:\app\Administrator\product\11.2.0\dbhome_2)
      (PROGRAM = extproc)
      (ENVS = "EXTPROC_DLLS=ONLY:E:\app\Administrator\product\11.2.0\dbhome_2\bin\oraclr11.dll")
    )
  )

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

ADR_BASE_LISTENER = E:\app\Administrator

tnsnames.ora

# tnsnames.ora Network Configuration File: E:\app\Administrator\product\11.2.0\dbhome_2\network\admin\tnsnames.ora
# Generated by Oracle configuration tools.

ORACLR_CONNECTION_DATA =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
    (CONNECT_DATA =
      (SID = CLRExtProc)
      (PRESENTATION = RO)
    )
  )

ORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.10.15)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = ORCL)
    )
  )

sqlnet.ora

# sqlnet.ora Network Configuration File: E:\app\Administrator\product\11.2.0\dbhome_2\network\admin\sqlnet.ora
# Generated by Oracle configuration tools.

# This file is actually generated by netca. But if customers choose to 
# install "Software Only", this file wont exist and without the native 
# authentication, they will not be able to connect to the database on NT.

SQLNET.AUTHENTICATION_SERVICES= (NTS)

NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)

【问题讨论】:

    标签: oracle oracle11g sqlplus ora-12514


    【解决方案1】:

    创建一个指向 tnsnames.ora 文件所在目录的环境变量 TNS_ADMIN。然后尝试连接sqlplus。

    如果可行,那么我猜你可能也安装了 Oracle 客户端软件,当你运行 sqlplus 时,它会在你的客户端主页中查找 tnsnames.ora 文件。

    -- windows中添加环境变量TNS_ADMIN的说明
    1. 进入控制面板/系统
    2.选择高级系统设置
    3.选择“高级”选项卡,环境变量按钮在底部。
    4. 创建新变量 TNS_ADMIN 并给出 .ora 文件的存储路径。例如C:\app\oracle\product\11.2.0\client_1\network\admin

    【讨论】:

    • 谢谢。这行得通。我还是不明白 tnsping 怎么能找到 tnsnames.ora 就好了,但是 sqlplus 需要环境变量的帮助?!
    • 为我修复的环境变量。奇怪的是,我已经为其他链接配置了 tnsnames.ora,并且它起作用了。当我添加新的时,tnsping 可以,但不是 sqlplus 连接,而旧的可以。添加环境变量后,新链接有效。
    • @Baodad,这取决于您安装的 Oracle 软件。如果您在多个地方安装了 sqlplus,这完全取决于您运行的是哪一个。
    【解决方案2】:

    如果你的密码中有一个@符号,Sqlplus 会给出这个错误,你这样做了。 Sqlplus 认为您正在输入连接字符串作为参数。更改您的密码(您可以使用 SQL Developer 执行此操作)。

    道德:不要在 Oracle 密码中使用 at 符号。

    【讨论】:

    • 在这里,我花了好几个小时摸摸自己做错了什么。 SQL*Plus 在密码字段中做的多么愚蠢的事情!非常感谢您的回答,我自己是想不通的。
    • 这是我的问题。我不会猜到,因为我没有使用连接的单个命令输入密码。我等待提示。这太荒谬了!
    【解决方案3】:

    tnslsnr 已启动但数据库已关闭。

    检查数据库是否正在运行

    ps aux | fgrep pmon
    

    如果没有这个进程,尝试手动启动数据库

    su - oracle
    export ORACLE_SID=XE
    sqlplus sys as sysdba
    

    然后在 sql 控制台中

    startup
    

    【讨论】:

      【解决方案4】:

      确保您的密码中没有像 @ 这样的特殊字符。它适用于我的情况。

      检查下面,如果显示无效密码,则特殊字符是原因。

      sqlplus anyword/anyword@yourServiceName
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-02-25
        • 2015-09-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多