oracle .net 中的 Windows 服务无法解析 tns 服务名称

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/704772/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 18:00:53  来源:igfitidea点击:

Windows Service in .net cannot resolve tns service name

.netoraclewindows-serviceswindows-server-2003

提问by David Evans

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.

我已将我们应用程序的一个组件从 Web 服务移至 Windows 服务。它从 web 服务完美地连接到 oracle,但拒绝从 Windows 服务中看到 Tns 名称。我已经完全控制了运行服务的帐户的 ORAHOME 目录。

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.

我还通过使用 runas regedit 作为服务帐户检查了对注册表的服务帐户权限,它可以看到 HKLM\SOFTWARE\ORACLE\HOME0 详细信息和 HKLM\SOFTWARE\ORACLE\ALL_HOMES。所有 ORACLE_HOME 键都指向同一个目录。

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

我可以以服务帐户身份登录并 TNSPing sid 'UAT' 没有问题:

'OK (70 msec)'

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.

我已将进程监视器附加到进程,并且服务帐户(最终在扫描了大部分注册表之后)看到了 tnsnames.ora 甚至读取了它。

Are you chuckling behind your keyboard? Can you help!

你在键盘后面笑吗?你能帮我吗!

Cause: OracleException

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()

回答by David Evans

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

首先,您可以更改连接字符串以展开 tns 条目:

Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.161.50.101)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=MOUAT)));Password=password;User Id=username;

Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.161.50.101)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=MOUAT)));Password=password;User Id=username;

Then you get the real error:

然后你会得到真正的错误:

And got ‘ORA-06413: Connection not open.'

And got ‘ORA-06413: Connection not open.'

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

这是由于“Windows 服务”路径中包含括号“(DEV)”或“(UAT)”

ANSWER: Expand out the connection string to exclude the TNS resolution and then make sure that the path to the calling application does not contain brackets '(' or ')'.

解答:展开连接字符串以排除 TNS 解析,然后确保调用应用程序的路径不包含方括号“(”或“)”。

回答by DCookie

Try setting the windows environment variable TNS_ADMIN to the path where the tnsnames.ora file resides and restarting your serivce.

尝试将 windows 环境变量 TNS_ADMIN 设置为 tnsnames.ora 文件所在的路径并重新启动您的服务。

回答by crb

Run Process Monitor to see if it's loading the TNSNAMES.ORA file. I suspect it is, but your name resolution is broken as that user.

运行进程监视器以​​查看它是否正在加载 TNSNAMES.ORA 文件。我怀疑是这样,但是作为该用户,您的名称解析被破坏了。

If you can log in interactively with the service account, try using tnsping to see if you can connect to the name.

如果您可以使用服务帐户交互登录,请尝试使用 tnsping 以查看是否可以连接到名称。

Oracle resolves files in this order (as per Metalink article 114085.1):

Oracle 按以下顺序解析文件(根据 Metalink 文章 114085.1):

  1. Oracle Net files in present working directory
  2. TNS_ADMIN defined as a user/session environment variable
  3. TNS_ADMIN defined as a global environment variable
  4. TNS_ADMIN defined in the registry
  5. Oracle Net files in %ORACLE_HOME%\network\admin (the Oracle default location)
  1. 当前工作目录中的 Oracle Net 文件
  2. TNS_ADMIN 定义为用户/会话环境变量
  3. TNS_ADMIN 定义为全局环境变量
  4. 注册表中定义的 TNS_ADMIN
  5. %ORACLE_HOME%\network\admin 中的 Oracle Net 文件(Oracle 默认位置)

See which, if any, are being read with Process Monitor.

查看正在使用 Process Monitor 读取的内容(如果有)。

回答by Martlark

Check that the service can access the registry entry with tells oracle where the tnsnames.ora file is located. From memory it is HKLM\SOFTWARE\ORACLE\Key_Client with a TNS_NAMES registry string which is the folder holding the tnsnames.ora file. You can also create the same thing in the HKCU tree.

通过告诉 oracle tnsnames.ora 文件所在的位置检查服务是否可以访问注册表项。根据记忆,它是 HKLM\SOFTWARE\ORACLE\Key_Client,带有 TNS_NAMES 注册表字符串,该字符串是保存 tnsnames.ora 文件的文件夹。您也可以在 HKCU 树中创建相同的内容。

Oops ! now i'm at work i can see the string name should be TNS_ADMIN. Also try the env variable TNS_ADMIN and make sure there is nothing in HKCU.

哎呀!现在我正在工作,我可以看到字符串名称应该是 TNS_ADMIN。还可以尝试使用环境变量 TNS_ADMIN 并确保 HKCU 中没有任何内容。

Noticed as well you need the sqlnet.ora file in the same folder as tnsnames.ora

还注意到您需要与 tnsnames.ora 位于同一文件夹中的 sqlnet.ora 文件

回答by kunal brahme

First of all check your operating system is it 32bit or 64bit. If it is 64bit then install oracle express edition 64bit then it will not generate any error and run successfully....

首先检查你的操作系统是32位还是64位。如果是 64bit 然后安装 oracle express edition 64bit 那么它不会产生任何错误并成功运行....

visit http://behindfutureworld.weebly.comfor more detail.....

访问http://behindfutureworld.weebly.com了解更多详情.....