Windows服务在.net中无法解析TNS服务名称名称、Windows、net、TNS

2023-09-03 21:22:56 作者:被自己宠坏的小仙女

我已经动了我们的应用程序的组件从Web服务到Windows服务。它连接到Oracle完全从web服务,但拒绝从Windows服务看到TNS名称。我已完全控制ORAHOME目录的服务正在运行下的帐户。

I have moved a component of our application from a webservice to a Windows Service. It connects to oracle perfectly from the webservice but refuses to see the Tns names from the Windows service. I have given full control to the ORAHOME dir to the account the service is running under.

我还检查了服务帐户权限注册表中使用的runas注册表编辑器作为服务帐户,它可以看到HKLM \ SOFTWARE \ ORACLE \ HOME0细节和HKLM \ SOFTWARE \ ORACLE \ ALL_HOMES。所有ORACLE_HOME键都指向同一个目录。

I have also checked the service account permission to the registry by using runas regedit as the service account and it can see HKLM\SOFTWARE\ORACLE\HOME0 details and HKLM\SOFTWARE\ORACLE\ALL_HOMES. All the ORACLE_HOME keys are pointing to the same directory.

我可以作为服务帐户和TNSPING的SIDUAT没有问题登录:  

I can log in as the service account and TNSPing the sid 'UAT' with no problems:

'OK (70 msec)'

我重视过程监控的过程和服务帐户是看到了tnsnames.ora中(最后扫描注册表的最后),甚至读取它。

I have attached process monitor to the process and the service account is (finally after scanning most of the registry) seeing the tnsnames.ora and even reads it.

您笑着键盘的背后?你能帮助!

Are you chuckling behind your keyboard? Can you help!

Cause: OracleException

来源:System.Data.OracleClient的 消息:ORA-12154:TNS:无法解析服务名称    在System.Data.ProviderBase.DbConnectionPool.GetConnection(的DbConnection owningObject)    在System.Data.ProviderBase.DbConnectionFactory.GetConnection(的DbConnection owningConnection)    在System.Data.ProviderBase.DbConnectionClosed.OpenConnection(的DbConnection outerConnection,DbConnectionFactory connectionFactory的)    在System.Data.OracleClient.OracleConnection.Open()

Source: System.Data.OracleClient Message: ORA-12154: TNS:could not resolve service name at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) at System.Data.OracleClient.OracleConnection.Open()

推荐答案

首先,您可以更改连接字符串,扩大了TNS项:

First you can change the connection string to expand out the tns entry:

数据Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.161.50.101)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=MOUAT)));Password=password;User ID =用户名;

然后你得到真正的错误:

Then you get the real error:

键,得到ORA-06413:未打开连接

这是由于有括号其中的Windows服务路径(DEV)或(UAT)

Which was due to the 'Windows Service' path having brackets in it '(DEV)' or '(UAT)'

答:展开了连接字符串排除TNS决议并确保该路径调用应用程序不包含括号'('或')