使用Oracle 11g的.NET Entity Framework

3
我正在使用Oracle提供的Entity Framework (Oracle.ManagedDataAccessDTC)。在Visual Studio中运行一切正常,但是当我将其发布到IIS时,会收到连接错误异常。
以下是我的WebConfig,在Visual Studio中正常工作:
<?xml version="1.0"?>
<configuration>

    <system.web>
        <compilation debug="true" targetFramework="4.0" />
    </system.web>
  <connectionStrings>
    <add name="Entities" connectionString="metadata=res://*/Model.Model.csdl|
         res://*/Model.Model.ssdl|
         res://*/Model.Model.msl;
         provider=Oracle.ManagedDataAccess.Client;
         provider connection string='DATA SOURCE=ORCL;PASSWORD=giovanni;USER ID=DB_ES'" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>

我在IIS上遇到了以下错误:

Server Error in '/EA' Application.

    ORA-12154: TNS:não foi possível resolver o identificador de conexão especificado

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: OracleInternal.Network.NetworkException: ORA-12154 could not resolve the connect identifier specified

    Source Error: 


    Line 24:         public List<CADASTRO> GetCadastroBy(string CPF, string Cartao)
    Line 25:         {
    Line 26:             return ent.CADASTRO.Where(x => x.CPF.Equals(CPF) && x.NUMEROSEUCARTAO.Equals(Cartao)).Select(x => x).ToList<CADASTRO>();
    Line 27:         }

在sql plus中查询正常。

大家有什么想法吗?

解决方案:

  <oracle.manageddataaccess.client>
    <version number="4.121.1.0">
      <settings>
        <setting name="TNS_ADMIN" value="C:\app\giovanni.saraiva\product\11.2.0\dbhome_2\network\admin"/>
      </settings>
    </version>
  </oracle.manageddataaccess.client>

在webconfig中。

1
你应该隐藏任何敏感数据,比如密码。 - Christian Phillips
1个回答

5

看起来托管驱动无法解析TNS名称。 您应确保您的配置正确(请参见文档)。

例如:

<oracle.manageddataaccess.client>
  ...
  <settings>
    ...
    <setting name="TNS_ADMIN" value="C:\path\where\TNSNAMESFILE\is"/>
    ...
  </settings>
  ...
</oracle.manageddataaccess.client>

此外,如果在machine.config中未定义,则可能需要配置提供程序工厂:
<system.data>
  <DbProviderFactories>

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

作为一种旁注,我注意到你提到了Oracle.ManagedDataAccessDTC作为托管驱动程序。请注意,Oracle.ManagedDataAccessDTC实际上是提供分布式事务支持的组件,而主驱动程序集被称为"Oracle.ManagedDataAccess"。

没错,你关于ManagedDataAccess的想法是正确的,我会尝试提供路径并查看结果。 - Moondustt

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接