配置好rac後,兩個節點用tnsping都可以ping通,但用sqlplus連接都出現以下錯誤,不知道哪裡出了問題
[oracle@rac2 admin]$ lsnrctl status
LSNRCTL for Linux: Version 9.2.0.4.0 - Production on 04-MAR-2008 08:32:26
Copyright (c) 1991, 2002, Oracle Corporation. All rights reserved.
Connecting to (DEscriptION=(ADDRESS=(PROTOCOL=TCP)(HOST=rac2)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 9.2.0.4.0 - Production
Start Date 04-MAR-2008 08:29:03
Uptime 0 days 0 hr. 3 min. 22 sec
Trace Level off
Security OFF
SNMP OFF
Listener Parameter File /home/oracle/9.2.0.4/network/admin/listener.ora
Listener Log File /home/oracle/9.2.0.4/network/log/listener.log
Listening Endpoints Summary...
(DEscriptION=(ADDRESS=(PROTOCOL=tcp)(HOST=rac2)(PORT=1521)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "esal" has 2 instance(s).
Instance "rac1", status READY, has 1 handler(s) for this service...
Instance "rac2", status READY, has 1 handler(s) for this service...
The command completed successfully
[oracle@rac2 admin]$ lsnrctl service
LSNRCTL for Linux: Version 9.2.0.4.0 - Production on 04-MAR-2008 08:32:32
Copyright (c) 1991, 2002, Oracle Corporation. All rights reserved.
Connecting to (DEscriptION=(ADDRESS=(PROTOCOL=TCP)(HOST=rac2)(PORT=1521)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0
LOCAL SERVER
Service "esal" has 2 instance(s).
Instance "rac1", status READY, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0 state:ready
REMOTE SERVER
(address=(protocol=tcp)(host=rac1)(port=1521))
Instance "rac2", status READY, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0 state:ready
LOCAL SERVER
The command completed successfully
[oracle@rac2 admin]$ sqlplus cy/zh@esal
SQL*Plus: Release 9.2.0.4.0 - Production on Tue Mar 4 08:32:45 2008
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
ERROR:
ORA-12154: TNS:could not resolve service name
Enter user-name:
ERROR:
ORA-01017: invalid username/password; logon denied
Enter user-name: cy/zh@rac1
ERROR:
ORA-12154: TNS:could not resolve service name
SP2-0157: unable to CONNECT to ORACLE after 3 attempts, exiting SQL*Plus
[oracle@rac2 admin]$ sqlplus cy/zh@rac2
SQL*Plus: Release 9.2.0.4.0 - Production on Tue Mar 4 08:32:59 2008
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
ERROR:
ORA-12154: TNS:could not resolve service name
Enter user-name:
按照如下過程,一般都能解決:
在虛擬機內開cmd,用lsnrctl status查看監聽器監聽的服務
如看到監聽服務“orcl”,那在本機的tns配置中(SERVICE_NAME = orcl)必須寫orcl;如果想要自定義,則在虛擬機內的listener配置中就要加入自定義服務名,記得要重啟監聽服務:lsnrctl reload
最後形成的配置文件如下
虛擬機listener:
SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = test) 自定義服務名 (ORACLE_HOME = E:oracleproduct10.2.0db_1) db_home (SID_NAME = test) ) (SID_DESC = (PROGRAM = extproc) (SID_NAME = PLSExtProc) (ORACLE_HOME = E:oracleproduct10.2.0db_1) ##這個服務保證你可以使用外部過程,如C程序 ) )
本機tns:
ORCL_XNJ = (DEscriptION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 182.12.15.232)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = test) 與自定義服務名對應 ) )
再次連接,問題解決!
記住,一定從最簡單的原因找起,不要一上去就看到網上的什麼改process數、注冊表之類的,要想想本機能連為什麼通過網絡就不行,還是定位問題。
VS2008連接oracle 出現錯誤 ora-12154 tns 無法解析指定的連接標示符
在保證你的代碼沒有錯誤的前提下:
(一)檢查OracleOraDb10g_home1TNSListener 服務有沒有啟動,即監聽服務
(二)檢查tnsnames.ora是否添加連接串(建議用SQLPLUS或者pl/sql測試),其路徑一般是:%Oracle_home%product10.2.0db_1NETWORKADMINtnsnames.ora
其它網友的補充:
今天裝oracle安裝都完成了,但出現了“ORA-12154 TNS”的錯誤,最開始以為是oracle安裝處了問題,但後來發現並不是,因為用SQL Plus可以登錄,只是用plsql登錄時才出現這錯,用360完全卸載了qlsql後,從新裝了次,還是那錯,郁悶。。。後來又把數據庫刪掉重新建立,還是不行,整了半天,最後自己都整暈了,算了,重頭再來吧。。。
百度下很多安裝圖解,按著來就成
oracle服務端安裝圖解
http://www.jb51.net/article/108555.htm
oracle客戶端安裝圖解
http://www.jb51.net/article/108556.htm
oracle完全卸載
http://www.jb51.net/article/96395.htm
或者直接在注冊表中按F3搜索oracle,刪除注冊文件,不過貌似文件有點多,操作有點慢,建議用上邊鏈接的方法
總結了下要注意的幾點
1.安裝服務端是一般選“基本安裝”就行
2.使用PLSQL Developer時,“ORA-12154 TNS無法解析指定的連接標識符”的問題
安裝時報後邊的錯“warning some oracle net versions cannot connect from a path with parentheses”,這錯原來提示了,不能有括號,修改了安裝路徑就沒有問題了
相應的上邊的“ORA-12154 TNS無法解析指定的連接標識符”錯也沒啦,有點暈,沒整明白,但確實好啦
3.“ORA-12154 TNS無法解析指定的連接標識符”按照網上的方法有兩種,但我試了,在我這都不好使,下邊貼出來,沒准兒啥時候可以用
1.解決辦法,修改PLSQL Developer的選項設置:
客戶端、服務器端Oracle軟件裝好之後,用PLSQL Devloper登錄時,點擊取消,進入PLSQL Developer主界面,菜單Tools-Preferences,在設置窗口中,選擇Oracle-Connection,對應設置窗口中,找到Oracle Home,選擇OraDb10g_home1,保存設置,重新登錄PLSQL Developer即可
2.修改D:\oracle\product\10.2.0\db_1\NETWORK\ADMIN路徑下的tnsnames.ora文件
###### 一般的配置 ##################################
ORALOCAL = (DEscriptION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = oralocal) ) )
以上答案供參考