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

  • Question

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

    I have created two projects

    1)One for Data access 2) MVC4 Web project.

    It is working fine If I am trying to connect using console Application and App.config,but facing issue when trying to connect using web application and we.config.

    I have added packages using Nuget in data access project.

    I referenced that data access dll in web project and trying to call the oracle coonection.

    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>

    My Web.Config file

    <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="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 getting the following error when trying to call the Data access project from MVC project.

    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.

    Wednesday, May 20, 2015 12:45 PM

Answers


  • Hi,

    I tried with the following and it started working.

    I just commented the  defaultConnectionFactory line in web.config

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


        </providers>

      </entityFramework>
    Friday, May 22, 2015 2:03 PM

All replies

  • Did you try installing EF in the MVC project as well? I remeber having to install EF in thc classlib project that directly used EF, and I had to install EF in the project that referenced the classlib project that used EF.
    Wednesday, May 20, 2015 5:23 PM

  • Hi,

    I tried with the following and it started working.

    I just commented the  defaultConnectionFactory line in web.config

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


        </providers>

      </entityFramework>
    Friday, May 22, 2015 2:03 PM