Creating a data model for an Oracle database occurs with an error or with the error "Could not find or load a registered .Net Framework data provider"

Summary

I am trying to create an Entity Framework model based on an Oracle database. Visual Studio "Entity Data Model Wizard" suddenly disappears without error messages halfway through the configuration. Using edmgenfrom the command line fails with Failed to find or load the registered .Net Framework Data Provider..

Description of the problem

Approach 1: create a model using the wizard

I have a new console application called EFConsoleApp. From NuGet, I have the most modern versions of EntityFramework, Oracle.ManagedDataAccess and Oracle.ManagedDataAccess.EntityFramework.

I use the menu "Add → New item ..." to add the ADO.NET entity data model project to the project.

enter image description here

enter image description here

I select "EF Designer from the database" in the first wizard window. (but the problem also occurs if I also try any other option).

enter image description here

I select my connection for data transfer from the drop-down list.

enter image description here

I click "Next." This blank window will appear. It does not respond to all user input and disappears after about five seconds.

enter image description here

Visual Studio returns to its normal state, but no model has been added, and my output panel has no new output (error or otherwise).

Approach 2: create a model using edmgen

In the admin command prompt window, run edmgen.

C:\Windows\system32>C:\Windows\Microsoft.NET\Framework64\v4.0.30319\edmgen /connectionstring:"DATA SOURCE=ORCL2;USER ID=REDACTED;PASSWORD=REDACTED" /mode:FullGeneration /project:EFConsoleApp /provider:Oracle.ManagedDataAccess.Client
EdmGen for Microsoft (R) .NET Framework version 4.6.1038.0
Copyright (C) Microsoft Corporation. All rights reserved.

error 7001: Failed to find or load the registered .Net Framework Data Provider.

Generation Complete -- 1 errors, 0 warnings

Fails.

additional information

readme Oracle.ManagedDataAccess.EntityFramework Oracle.ManagedDataAccess, app.config . <section> oracle.manageddataaccess.client, machine.config.

  <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.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
  </configSections>

  ...

  <oracle.manageddataaccess.client>
    <version number="*">
      <dataSources>
        <dataSource alias="ORCL2" descriptor="(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = orcl2)))"/>
      </dataSources>
    </version>
  </oracle.manageddataaccess.client>
  <connectionStrings>
    <add name="MyContext"      providerName="Oracle.ManagedDataAccess.Client" connectionString="DATA SOURCE=ORCL2;USER ID=REDACTED;PASSWORD=REDACTED"/>
  </connectionStrings>

Oracle.ManagedDataAccess GAC.

C:\Windows\system32>gacutil -l Oracle.ManagedDataAccess
Microsoft (R) .NET Global Assembly Cache Utility.  Version 4.0.30319.0
Copyright (c) Microsoft Corporation.  All rights reserved.

The Global Assembly Cache contains the following assemblies:
  Oracle.ManagedDataAccess, Version=4.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=MSIL

Number of items = 1

My machine.config Oracle.ManagedDataAccess.Client.

<configuration>
  <configSections>
    ...
    <section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
    ...
  </configSections>
  ...
  <system.data>
    <DbProviderFactories>
      <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.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
      ...
    </DbProviderFactories>
  </system.data>
  ...
  <oracle.manageddataaccess.client>
    <version number="4.122.1.0">
      <settings>
        <setting name="TNS_ADMIN" value="C:\app\oracle_user\client\network\admin"/>
      </settings>
    </version>
  </oracle.manageddataaccess.client>
</configuration>

Oracle Oracle.ManagedDataAccess.Client, OracleConnection .

using System;
using Oracle.ManagedDataAccess.Client;

namespace EFConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            OracleConnection con = new OracleConnection();

            //using connection string attributes to connect to Oracle Database
            con.ConnectionString = "User Id=REDACTED;Password=REDACTED;Data Source=ORCL2";
            con.Open();
            Console.WriteLine("Connected to Oracle" + con.ServerVersion);

            OracleCommand cmd = con.CreateCommand();
            cmd.CommandText = "select * from REDACTED";
            OracleDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                Console.WriteLine(reader.GetInt32(0));
            }

            // Close and Dispose OracleConnection object
            con.Close();
            con.Dispose();
            Console.WriteLine("Disconnected");
            Console.ReadLine();
        }
    }
}

enter image description here

Oracle Visual Studio. readme, " ":

" .NET Framework", - machine.config. , Oracle Data Provider .NET machine.config.xml DbProviderFactories , . , machine.config Oracle .NET DbProviderFactories.

, ODP.NET, - DbProviderFactories.

, ?

+4

Source: https://habr.com/ru/post/1694816/


All Articles