ORA-12154&TNS-03505 案例分享2
2025-10-23 09:58 瀟湘隱者 閱讀(13) 評(píng)論(0) 收藏 舉報(bào)前幾天遇到了ORA-12154&TNS-03505這個(gè)錯(cuò)誤, 因?yàn)閷?duì)其數(shù)據(jù)庫(kù)環(huán)境不了解, 遠(yuǎn)程登錄過去檢查的時(shí)候, 了解到一些大概情況:此數(shù)據(jù)庫(kù)安裝在Windows服務(wù)器.遠(yuǎn)程客戶端能登錄數(shù)據(jù)庫(kù),但是本地服務(wù)器使用普通賬號(hào)登錄數(shù)據(jù)庫(kù)時(shí)報(bào)ORA-12154錯(cuò)誤,如下所示:
C:\Users\Administrator>sqlplus <user_name>/<passwod>@test
SQL*Plus: Release 19.0.0.0.0 - Production on Thu Oct 16 08:35:04 2025
Version 19.23.0.0.0
Copyright (c) 1982, 2023, Oracle. All rights reserved.
ERROR:
ORA-12154: TNS:could not resolve the connect identifier specified
Enter user-name:
使用tnsping檢查報(bào)TNS-03505錯(cuò)誤,如下所示:
C:\Users\Administrator>tnsping test
TNS Ping Utility for 64-bit Windows: Version 19.0.0.0.0 - Production on 14-OCT-2025 17:04:05
Copyright (c) 1997, 2024, Oracle. All rights reserved.
Used parameter files:
D:\App\Oracle19c\product\19.3\db_1\network\admin\sqlnet.ora
TNS-03505: Failed to resolve name
檢查D:\App\Oracle19c\product\19.3\db_1\network\admin\tnsnames.ora中的網(wǎng)絡(luò)服務(wù)名test的配置信息, 完全正確.沒有任何問題.然后仔細(xì)檢查,發(fā)現(xiàn)Windows環(huán)境變量中有兩個(gè)Oracle Client的配置(當(dāng)時(shí)不了解這些情況),具體如下所示:

C:\Users\Administrator>echo %path%
D:\App\Oracle19c\product\19.3\db_1\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;D:\Nuzarsurf\oracle_client\x64;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;
檢查后發(fā)現(xiàn)這臺(tái)機(jī)器上其實(shí)不僅僅安裝了Oracle數(shù)據(jù)庫(kù)軟件,還安裝一個(gè)Oracle instance client(D:\Nuzarsurf\oracle_client\x64), 由于環(huán)境變量的順序設(shè)置,決定了其優(yōu)先級(jí),此時(shí)讀取的是Oracle instance client下的網(wǎng)絡(luò)服務(wù)名,而這位朋友在(D:\App\Oracle19c\product\19.3\db_1\network\admin\tnsnames.ora)這個(gè)路徑下面的tnsnames.ora設(shè)置的網(wǎng)絡(luò)服務(wù)名,其實(shí)此時(shí)沒有生效,其實(shí)要么在(D:\Nuzarsurf\oracle_client\x64)路徑中的tnsnames.ora設(shè)置網(wǎng)絡(luò)服務(wù)名,可以解決這個(gè)問題.也可以通過調(diào)整PATH的先后順序解決這個(gè)問題. 如下所示:
我的電腦->屬性->高級(jí)->環(huán)境變量,找到PATH變量進(jìn)行順序調(diào)整
另外,出現(xiàn)ORA-12154 & TNS-03505還有其它原因,2016年曾經(jīng)總結(jié)過一篇ORA-12154 & TNS-03505 案例分享. 相同錯(cuò)誤,不同案例. 這里就不重復(fù)展開了。
浙公網(wǎng)安備 33010602011771號(hào)