簡體   English   中英

TNSPING 可以,但 sqlplus 給出 ORA-12154?

[英]TNSPING OK but sqlplus gives ORA-12154?

我在 Windows 服務器上運行 Oracle 11,並且我登錄到同一台服務器上嘗試使用 SQL Plus。 當我嘗試連接時,即使 TNSPING 和其他各種診斷看起來正常,我也會收到 ORA-12154。

誰能建議為什么? 下面詳細介紹。


如果我像這樣使用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

以下是各種配置文件:

聽者.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)

創建一個指向 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

如果您的密碼中有 at 符號 (@),Sqlplus 將給出此錯誤。 Sqlplus 認為您正在輸入連接字符串作為參數。 更改您的密碼(您可以使用 SQL Developer 執行此操作)。

道德:不要在 Oracle 密碼中使用 at 符號。

tnslsnr已啟動但數據庫已關閉。

檢查數據庫是否正在運行

ps aux | fgrep pmon

如果沒有這個進程,嘗試手動啟動數據庫

su - oracle
export ORACLE_SID=XE
sqlplus sys as sysdba

然后在 sql 控制台中

startup

確保密碼中沒有@ 等特殊字符。 在我的情況下確實如此。

檢查下面,如果它顯示無效的密碼,則特殊字符是原因。

sqlplus anyword/anyword@yourServiceName

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM