最新更新(2011年11月2日上午9時) 我試圖運行從服務用tnsping和有用! 但是當我嘗試連接時,仍然收到錯誤12154。我現在完全困惑,我不明白如何tnsping可以正常工作,但連接無法解析服務名稱。無法從Windows服務連接到Oracle(:ORA-12154:TNS:錯誤無法解析服務名稱(12154))
出於某種原因,當我運行從Windows服務下面的代碼(在定時器事件),我得到的錯誤:ORA-12154:TNS:無法解析服務名稱(12154)
當我運行完全相同的代碼從Windows窗體應用程序,它連接就好了。服務和應用都在我的帳戶下運行,因此帳戶權限沒有區別。
我很困惑,爲什麼服務失敗,任何人都可以點亮這個請嗎?
string connectionString = ";DSN=o1;UID=SCOTT;PWD=TIGER;DBQ=ORCL;DBA=W;APA=T;EXC=F;FEN=T;QTO=T;FRC=10;FDL=10;LOB=T;RST=T;GDE=F;FRL=F;BAM=IfAllSuccessful;MTS=F;MDI=F;CSR=F;FWC=F;PFC=10;TLO=0;";
OdbcConnection cnn;
cnn = new OdbcConnection(connectionString);
try
{
cnn.Open();
myEventLog.WriteEntry("Connection SUCCEEDED!!!");
cnn.Close();
}
catch (Exception ex)
{
string mes = "Connection FAILED!!!" + ex.Message;
myEventLog.WriteEntry(mes);
}
更新:
1)我試過用系統和用戶DSN,都具有相同的行爲
2)我添加了一個TNS_ADMIN系統環境變量,以使起訴它可以找到tnsnames.ora文件。這並沒有改變行爲。
最新更新(2011年11月1日):
1)很多的建議,都涉及把Oracle服務器的IP地址的連接字符串中繞過tnsnames.ora文件。不幸的是,該應用程序必須使用用戶設置的Oracle連接,所以我們沒有任何這些信息。我所要做的就是DSN。我必須使用Oracle DSN從Windows服務進行連接。
新更新(2011年11月2日): 1)它看起來像服務IS成功地讀取tnsnames.ora文件。我跑的過程監控,並得到這些行:
7:52:54.4365217 AM OracleService.exe 4624 CreateFile C:\oracle\ora92\network\Names\sdns.ora NAME NOT FOUND Desired Access: Generic Read, Disposition: Open, Options: Synchronous IO Non-Alert, Non-Directory File, Attributes: N, ShareMode: Read, Write, AllocationSize: n/a
7:52:54.4368466 AM OracleService.exe 4624 CreateFile C:\Windows\SysWOW64\tnsnames.ora NAME NOT FOUND Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a
7:52:54.4371203 AM OracleService.exe 4624 CreateFile C:\oracle\ora92\network\ADMIN\tnsnames.ora SUCCESS Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened
7:52:54.4372693 AM OracleService.exe 4624 QueryBasicInformationFile C:\oracle\ora92\network\ADMIN\tnsnames.ora SUCCESS CreationTime: 01/11/2011 3:10:08 PM, LastAccessTime: 01/11/2011 3:10:08 PM, LastWriteTime: 01/11/2011 3:10:42 PM, ChangeTime: 01/11/2011 3:18:44 PM, FileAttributes: A
7:52:54.4372866 AM OracleService.exe 4624 CloseFile C:\oracle\ora92\network\ADMIN\tnsnames.ora SUCCESS
7:52:54.4375418 AM OracleService.exe 4624 CreateFile C:\oracle\ora92\network\ADMIN SUCCESS Desired Access: Read Data/List Directory, Synchronize, Disposition: Open, Options: Directory, Synchronous IO Non-Alert, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened
7:52:54.4375857 AM OracleService.exe 4624 QueryDirectory C:\oracle\ora92\network\ADMIN\tnsnames.ora SUCCESS Filter: tnsnames.ora, 1: tnsnames.ora
7:52:54.4376192 AM OracleService.exe 4624 CloseFile C:\oracle\ora92\network\ADMIN SUCCESS
7:52:54.4377770 AM OracleService.exe 4624 CreateFile C:\oracle\ora92\network\ADMIN\tnsnames.ora SUCCESS Desired Access: Generic Read, Disposition: Open, Options: Synchronous IO Non-Alert, Non-Directory File, Attributes: N, ShareMode: Read, Write, AllocationSize: n/a, OpenResult: Opened
7:52:54.4379306 AM OracleService.exe 4624 ReadFile C:\oracle\ora92\network\ADMIN\tnsnames.ora SUCCESS Offset: 0, Length: 337, Priority: Normal
7:52:54.4380061 AM OracleService.exe 4624 ReadFile C:\oracle\ora92\network\ADMIN\tnsnames.ora END OF FILE Offset: 337, Length: 4,096
7:52:54.4380276 AM OracleService.exe 4624 CloseFile C:\oracle\ora92\network\ADMIN\tnsnames.ora SUCCESS
7:52:54.4385823 AM OracleService.exe 4624 CreateFile C:\oracle\ora92\network\ADMIN\ldap.ora NAME NOT FOUND Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a
因此,沒有人有任何想法,爲什麼它會讀取tnsnames.ora文件後失敗?謝謝
由於它的工作原理,當你運行它,我會假設你的tnsnames.ora配置是否正確。您正在連接的ODBC DSN設置爲系統DNS或用戶DSN嗎? – Tridus
我試過用系統和用戶dsn,都有相同的行爲。 –
您使用的是哪個版本的Windows? – WaldiMen