无法从Windows服务连接到Oracle(错误:ORA-12154:TNS:无法解析服务名称(12154)) [英] Can't connect to Oracle from a windows service (error: ORA-12154: TNS:could not resolve service name (12154) )

查看:132
本文介绍了无法从Windows服务连接到Oracle(错误:ORA-12154:TNS:无法解析服务名称(12154))的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最新更新(2011年11月2日上午9点) 我尝试从该服务运行tnsping,它起作用了! 但是,当我尝试连接时,我仍然收到错误12154.我现在很困惑,我不明白tnsping如何正常工作,但是连接无法解析服务名称.

LATEST Update (Nov 2 2011 9AM) I tried running tnsping from the service and it WORKS! However i still get error 12154 when i try to connect. I'm completely confused now, i can't understand how tnsping could work fine but the connection is unable to resolve the service name.

出于某种原因,当我从Windows服务(在计时器事件上)运行以下代码时,出现错误:ORA-12154:TNS:无法解析服务名称(12154)

For some reason when i run the following code from a windows service (on a timer event) I get the error: ORA-12154: TNS:could not resolve service name (12154)

当我从Windows窗体应用程序运行完全相同的代码时,它连接得很好.服务和应用程序都在我的帐户下运行,因此帐户权限没有区别.
我对为什么服务失败感到困惑,请问有人可以对此有所了解吗?

When i run the exact same code from a windows form app, it connects just fine. Both the service and the app are running under my account, so there is no difference in the account permissions.
I'm baffled as to why the service fails, can anyone shed some light on this please?

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和用户dsn,两者的行为相同

1) I've tried with both system and user dsn, both have the same behaviour

2)我在系统环境变量中添加了TNS_ADMIN,以使其可以找到tnsnames.ora文件.这并没有改变行为.

2) I added a TNS_ADMIN to the system environment variables to make sue it can find the tnsnames.ora file. This did not change the behaviour.

新更新(2011年11月1日):

New Updates (Nov 1 2011):

1)许多建议涉及将Oracle服务器的IP地址放在连接字符串中以绕过tnsnames.ora文件.不幸的是,该应用程序必须与用户设置的oracle连接配合使用,因此我们没有任何信息.我需要处理的只是一个DSN.我必须使它使用Oracle DSN从Windows服务连接.

1) A lot of the suggestions have involved putting the ip address of the Oracle server in the connection string to bypass the tnsnames.ora file. Unfortunately the app has to work with a user set oracle connection, so we don't have any of that information. All i have to work with is a DSN. I have to make it connect from a windows service using an Oracle DSN.

新更新(2011年11月2日): 1)服务似乎已成功读取tnsnames.ora文件.我运行了流程监视器,并得到了以下几行:

New Updates (Nov 2 2011): 1) It looks like the service IS successfully reading the tnsnames.ora file. I ran process monitor and got these lines:

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文件后它可能会失败?谢谢

So does anyone have any idea why it might be failing after reading the tnsnames.ora file? Thanks

推荐答案

好的,我将在这里回答我自己的问题,只是为了使最终解决方案与帮助我解决该问题的有用建议区分开. Nicola引用的帖子(一旦我仔细阅读后)竟然找到了答案.我的服务是从Program Files(x86)运行的,并且oracle驱动程序无法处理调用应用程序路径中的().
我将我的服务移至D:\ ServiceTest,并且工作正常. 我现在的问题是,我认为我们的应用程序不能移出程序文件(x86).
谢谢大家的帮助,感谢大家的投入,但我要感谢Nicola,因为他指出了我的答案. 再次感谢您的所有帮助

OK, I'm going to answer my own question here just to keep the final resolution separate from the helpful suggestions that led me to it. The post referenced by Nicola )once I read it carefully) turned out to have the answer. My service was running from Program Files(x86) and the oracle driver can NOT handle ( ) in the path of the calling app.
I moved my service to D:\ServiceTest and it works fine. My problem now is that I don't think our app can be moved out of Program Files (x86).
Thank you all for your help, I appreciate everyone's input but I will have to give the bounty to Nicola, as he pointed me to the post that contained the answer. Thanks again for all your help

这篇关于无法从Windows服务连接到Oracle(错误:ORA-12154:TNS:无法解析服务名称(12154))的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆