0

There are a number of questions on SO already for this issue. However, none of the answers provided that I've found have been of any help. We have an ASP.NET Core MVC project, targeting net461 so that we can use Entity Framework 6 for an Oracle database.

Related questions

Myself and all the other developers have it working fine on our PCs. When deploying to an IIS server, however, I get the following:

Error ::Schema specified is not valid. Errors:
Oracle.ManagedDataAccess.EntityFramework.Resources.EFOracleStoreSchemaDefinition.ssdl(2,64) : error 0175: The ADO.NET provider with invariant name 'Oracle.DataAccess.Client' is either not registered in the machine or application config file, or could not be loaded. See the inner exception for details.
Oracle.ManagedDataAccess.EntityFramework.Resources.EFOracleStoreSchemaDefinitionVersion3.ssdl(3,4) : error 0019: The EntityContainer name must be unique. An EntityContainer with the name 'Schema' is already defined.
Oracle.ManagedDataAccess.EntityFramework.Resources.EFOracleStoreSchemaDefinitionVersion3.ssdl(867,4) : error 0019: Each type name in a schema must be unique. Type name 'Oracle.Table' was already defined.
Oracle.ManagedDataAccess.EntityFramework.Resources.EFOracleStoreSchemaDefinitionVersion3.ssdl(877,4) : error 0019: Each type name in a schema must be unique. Type name 'Oracle.TableColumn' was already defined.
... and so on.

Although I've seen posted that the Oracle.ManagedDataAccess.dll is all you should need to connect to Oracle, I have installed oth the 11g and 12c 64 bit Oracle clients on the server. If I open the 64bit ODBC Administrator tool, I am able to connect to the DB from our server, meaning there are no connection issues.

The error message mentions Oracle.DataAccess.Client, but we are using Oracle.ManagedDataAccess.Client. Nowhere in our code, .csproj's, or packages.config do we reference the non-managed dll. I have tried various <clear /> and <remove> tags inside of <DbProviderFactories>. I have copied the Oracle.DataAccess.dll from the Oracle client install location directly into the project folder. I have uninstalled, re-installed, re-deployed. I have added both DLL's to the GAC. Nothing seems to get rid of that error.

Here are the relevant parts of the 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.122.18.3, Culture=neutral, PublicKeyToken=89b483f429c47342" />
  </configSections>
  <entityFramework>
    <providers>
      <provider invariantName="Oracle.ManagedDataAccess.Client" type="Oracle.ManagedDataAccess.EntityFramework.EFOracleProviderServices, Oracle.ManagedDataAccess.EntityFramework, Version=6.122.18.3, Culture=neutral, PublicKeyToken=89b483f429c47342" />
    </providers>
  </entityFramework>
  <system.data>
    <DbProviderFactories>
      <clear />
      <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>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <publisherPolicy apply="no" />
        <assemblyIdentity name="Oracle.ManagedDataAccess" publicKeyToken="89b483f429c47342" culture="neutral" />
        <bindingRedirect oldVersion="4.121.0.0 - 4.65535.65535.65535" newVersion="4.122.18.3" />
      </dependentAssembly>        
      ...         
  <connectionStrings>
    <add name="<DB_MODEL_NAME>" connectionString="metadata=res://*/;provider=Oracle.ManagedDataAccess.Client;provider connection string='<CONNECTION_STRING>'" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>

Note the metadata=res://*/ bit in the connection string. On our PCs, this reads as res://*/<DB_MODEL_NAME>.csdl|res://*/<DB_MODEL_NAME>.ssdl|res://*/<DB_MODEL_NAME>.msl. I updated it to metadata=res://*/ per some other posts. Without this, the error thrown is:

Error ::Unable to load the specified metadata resource.

I've tried suggestions from this article but none seem to work. If I give it the assembly name that contains the .edmx, it complains that it cannot find that DLL, even though it's right there in the deployed folder.

neilsimp1
  • 1,242
  • 1
  • 11
  • 25

2 Answers2

0

Neil

A few questions to help answer.

Are you using the Entity Framework Core?

Are you using the Oracle Managed Library? Can you connect to the DB Server from the App/Web Server at all? Have you tried using a simple console app to connect to the database from the server from the app/web server?

Also, from an architecture standpoint. https://learn.microsoft.com/en-us/aspnet/core/data/entity-framework-6?view=aspnetcore-2.2

It is best to: To use Entity Framework 6, your project has to compile against .NET Framework, as Entity Framework 6 doesn't support .NET Core. If you need cross-platform features you will need to upgrade to Entity Framework Core. The recommended way to use Entity Framework 6 in an ASP.NET Core application is to put the EF6 context and model classes in a class library project that targets the full framework. Add a reference to the class library from the ASP.NET Core project. See the sample Visual Studio solution with EF6 and ASP.NET Core projects. You can't put an EF6 context in an ASP.NET Core project because .NET Core projects don't support all of the functionality that EF6 commands such as Enable-Migrations require. But, first lets solve the first issue.

Peter
  • 1
  • We are using Entity Framework 6, not the Core version, since Oracle has yet to release a provider for EF Core. We are using the `Oracle.ManagedDataAccess` library. We are able to connect to the DB from the app server via ODBC administrator. We have not tried it with a simple console app. The project is compiled to run under `net461`. The article you linked to is what I followed to set this up. – neilsimp1 Jan 04 '19 at 17:33
0

Neil,

ODP.NET and EF6 configuration on ASP.NET Core targeting .NET 4.7.2

See the difference in the versioning from yours.

Peter
  • 1