Facing Issue while connecting Entity framework with Oracle 11g using MVC 4

asp.net-mvc-4 entity-framework entity-framework-6 oracle oracle11g

Question

I am trying to connect to an Oracle Database through Entity Framework.

I have created two projects:

  1. A data access project
  2. MVC4 Web project

It is working fine if I try to connect using a console application and App.config, but facing issue when trying to connect using web application and web.config.

I have added packages using Nuget in data access project. I referenced the data access dll in web project and trying to call the oracle connection.

Package.config

<packages>    
  <package id="EntityFramework" version="6.0.2" targetFramework="net45" />    
  <package id="odp.net.x64" version="112.3.20" targetFramework="net45" />    
  <package id="Oracle.ManagedDataAccess" version="12.1.021" targetFramework="net45" />    
  <package id="Oracle.ManagedDataAccess.EntityFramework" version="12.1.021" targetFramework="net45" />    
</packages>

Web.Config

<configuration>    
  <configSections>    
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->    
    <section name="entityFramework"    
             type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"    
             requirePermission="false"/>
    <section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />    
  </configSections>

  <connectionStrings>    
    <clear/>   
    <add name="OracleDbContext" providerName="Oracle.ManagedDataAccess.Client"    
         connectionString=" Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=host address)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=oracle))); User Id=userid;Password=pwd;"/>    
  </connectionStrings>

  <entityFramework>    
    <!--<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>-->    
    <defaultConnectionFactory type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" >    
    </defaultConnectionFactory>

    <providers>    
      <provider invariantName="Oracle.ManagedDataAccess.Client"  
          type="Oracle.ManagedDataAccess.EntityFramework.EFOracleProviderServices, Oracle.ManagedDataAccess.EntityFramework, Version=6.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>    
    </providers>  

  </entityFramework>

  <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.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />    
    </DbProviderFactories>   
  </system.data>

  <runtime>    
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <publisherPolicy apply="no"/>
        <assemblyIdentity name="Oracle.ManagedDataAccess" publicKeyToken="89b483f429c47342" culture="neutral" />
      </dependentAssembly>
    </assemblyBinding>    
  </runtime>

  <oracle.manageddataaccess.client>    
    <version number="*">    
      <dataSources>    
        <dataSource alias="OracleDbContext" descriptor="(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=hostname)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=oracle))); User Id=userid;Password=pwd;"/>    
      </dataSources>    
    </version>    
  </oracle.manageddataaccess.client>    
</configuration>

I am facing the issue below:

The Entity Framework provider type 'Oracle.ManagedDataAccess.EntityFramework.EFOracleProviderServices, Oracle.ManagedDataAccess.EntityFramework, Version=6.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342' registered in the application config file for the ADO.NET provider with invariant name 'Oracle.ManagedDataAccess.Client' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.

Please let me know how can I solve this issue.

1
2
5/20/2015 8:26:19 PM

Popular Answer

You have to give a proper assembly qualified name.

If you are not sure of it, you can check what the name is using AssemblyName.GetAssemblyName(@""). And copy it to your config.

For more information, see https://msdn.microsoft.com/en-us/library/2exyydhb(v=vs.110).aspx

I had faced the exact same error. This solution worked fine.

0
2/13/2017 10:13:52 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow