Oracle.ManagedDataAccess: TNS: 无法解析指定的连接标识符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23475594/
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
Oracle.ManagedDataAccess: TNS:could not resolve the connect identifier specified
提问by Andy
I'm getting the following error while trying to connect to an Oracle database from a new ASP.NET MVC 4 application: "ORA-12154: TNS:could not resolve the connect identifier specified". I'm using the Oracle.ManagedDataAccess DLL (version 4.121.1.0) to try to connect to an Oracle 10g database. Here's the thing - I have an integration test assembly that is successfully connecting to the database using this minimal App.config:
尝试从新的 ASP.NET MVC 4 应用程序连接到 Oracle 数据库时出现以下错误:“ORA-12154:TNS:无法解析指定的连接标识符”。我正在使用 Oracle.ManagedDataAccess DLL(版本 4.121.1.0)尝试连接到 Oracle 10g 数据库。事情就是这样 - 我有一个集成测试程序集,它使用这个最小的 App.config 成功连接到数据库:
<connectionStrings>
<add name="OracleConnection" connectionString="DATA SOURCE=TNS_NAME;PASSWORD=xxx;PERSIST SECURITY INFO=True;USER ID=xxx" providerName="Oracle.ManagedDataAccess.Client" />
</connectionStrings>
However, if I try to run my web app with all the crazy Web.config settings, I'm getting the error "ORA-12154: TNS:could not resolve the connect identifier specified". What am I doing wrong? Why is my config for the integration test assembly so simple and the Web.config so complex? Here's the pertinent sections of my Web.config (taken from Deploying and Configuring ODP.NET to work without installation with Entity Framework):
但是,如果我尝试使用所有疯狂的 Web.config 设置运行我的 Web 应用程序,则会收到错误“ORA-12154:TNS:无法解析指定的连接标识符”。我究竟做错了什么?为什么我的集成测试程序集配置如此简单而 Web.config 如此复杂?这是我的 Web.config 的相关部分(取自部署和配置 ODP.NET 以在不安装实体框架的情况下工作):
custom configSection:
自定义配置部分:
<configSections>
<section name="oracle.manageddataaccess.client"
type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
</configSections>
the corresponding config section:
相应的配置部分:
<oracle.manageddataaccess.client>
<version number="*">
<edmMappings>
<edmMapping dataType="number">
<add name="bool" precision="1"/>
<add name="byte" precision="2" />
<add name="int16" precision="5" />
</edmMapping>
</edmMappings>
</version>
</oracle.manageddataaccess.client>
custom system.data node:
自定义 system.data 节点:
<system.data>
<DbProviderFactories>
Remove in case this is already defined in machine.config
<remove invariant="Oracle.DataAccess.Client" />
<remove invariant="Oracle.ManagedDataAccess.Client" />
<add name="ODP.NET, Managed Driver" invariant="Oracle.ManagedDataAccess.Client"
description="Oracle Data Provider for .NET, Managed Driver"
type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
</DbProviderFactories>
</system.data>
EntityFramework node:
实体框架节点:
<entityFramework>
<defaultConnectionFactory type="Victoria.Data.OracleConnectionFactory, EntityFramework" />
</entityFramework>
Update 1: After reading through http://docs.oracle.com/cd/E16655_01/win.121/e17732/featConfig.htm#ODPNT8161, I tried modifying my Web.config oracle.manageddataaccess.client to the following and it works. However, it doesn't seem right to have the connectionString node referencing the TNS name AND this extra reference to the same TNS Names file.
更新 1:通过http://docs.oracle.com/cd/E16655_01/win.121/e17732/featConfig.htm#ODPNT8161阅读后,我尝试将我的 Web.config oracle.manageddataaccess.client 修改为以下内容并且它有效. 但是,让 connectionString 节点引用 TNS 名称和对同一个 TNS 名称文件的额外引用似乎并不正确。
<oracle.manageddataaccess.client>
<version number="*">
<dataSources>
<dataSource alias="SIEBMATS" descriptor="(DESCRIPTION=(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = xxx.yyy.zzz)(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME = siebmats)))" />
</dataSources>
<edmMappings>
<edmMapping dataType="number">
<add name="bool" precision="1"/>
<add name="byte" precision="2" />
<add name="int16" precision="5" />
</edmMapping>
</edmMappings>
</version>
</oracle.manageddataaccess.client>
回答by Anarud
One thing you can try is having the connection string like so: connectionString="Data Source=//SERVER:PORT/INSTANCE_NAME;USER=XXX;PASSWORD=XXX".
您可以尝试的一件事是使用如下连接字符串:connectionString="Data Source=//SERVER:PORT/INSTANCE_NAME;USER=XXX;PASSWORD=XXX"。
Useful references here: http://www.connectionstrings.com/oracle/http://docs.oracle.com/cd/E51173_01/win.122/e17732/featConnecting.htm#ODPNT169
有用的参考资料:http: //www.connectionstrings.com/oracle/ http://docs.oracle.com/cd/E51173_01/win.122/e17732/featConnecting.htm#ODPNT169
This has also helped me while having problems with EF: Deploying and Configuring ODP.NET to work without installation with Entity Framework
这在遇到 EF 问题时也对我有所帮助: 部署和配置 ODP.NET 无需安装实体框架即可工作
Hope to have helped.
希望有所帮助。
回答by Piotr Grudzień
My problem was in incorrect/incomplete Oracle Driver version, had 11.2.0 installed. I add another 12.2.0 version, didn't change anything in web.config and it worked as charm
我的问题是不正确/不完整的 Oracle 驱动程序版本,安装了 11.2.0。我添加了另一个 12.2.0 版本,在 web.config 中没有改变任何东西,它很有魅力