asp.net – Oracle.ManagedDataAccess:TNS:无法解析指定的连接标识符

前端之家收集整理的这篇文章主要介绍了asp.net – Oracle.ManagedDataAccess:TNS:无法解析指定的连接标识符前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
尝试从新的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>

但是,如果我尝试使用所有疯狂的Web.config设置运行我的Web应用程序,我收到错误“ORA-12154:TNS:无法解析指定的连接标识符”.我究竟做错了什么?为什么我的集成测试程序集的配置如此简单,Web.config如此复杂?这是我的Web.config的相关部分(取自Deploying and Configuring ODP.NET to work without installation with Entity Framework):

自定义configSection:

<configSections>
    <section name="oracle.manageddataaccess.client"
        type="OracleInternal.Common.ODPMSectionHandler,Oracle.ManagedDataAccess,Version=4.121.1.0,Culture=neutral,PublicKeyToken=89b483f429c47342" />
  </configSections>

相应的配置部分:

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

自定义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,PublicKeyToken=89b483f429c47342" />
    </DbProviderFactories>
  </system.data>

EntityFramework节点:

<entityFramework>
    <defaultConnectionFactory type="Victoria.Data.OracleConnectionFactory,EntityFramework" />
  </entityFramework>

更新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>

解决方法

您可以尝试的一件事是连接字符串如下:
connectionString =“Data Source = // SERVER:PORT / INSTANCE_NAME; USER = XXX; PASSWORD = XXX”.

这里有用的参考:
http://www.connectionstrings.com/oracle/
http://docs.oracle.com/cd/E51173_01/win.122/e17732/featConnecting.htm#ODPNT169

这对EF有问题也有帮助:
Deploying and Configuring ODP.NET to work without installation with Entity Framework

希望有所帮助.

猜你在找的asp.Net相关文章