5

Executive Summary

I'm trying to generate an Entity Framework model based on an Oracle database. Visual Studio's "Entity Data Model Wizard" abruptly vanishes with no error messages halfway through setup. Using edmgen from the command line fails with Failed to find or load the registered .Net Framework Data Provider..

Problem Description

Approach 1: generating the model with the wizard

I have a fresh new console application named EFConsoleApp. From NuGet, I have the most up-to-date versions of EntityFramework, Oracle.ManagedDataAccess, and Oracle.ManagedDataAccess.EntityFramework.

I use the "Add -> New Item..." menu to add an ADO.NET Entity Data Model to my project.

enter image description here

enter image description here

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

enter image description here

I select my data connection from the drop down list.

enter image description here

I click "next". This blank window appears. It is unresponsive to all user input, and vanishes after about five seconds.

enter image description here

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

Approach 2: generating the model with edmgen

From an administrator command window, I execute 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

It fails.

Additional Details

Pursuant to the readme instructions of Oracle.ManagedDataAccess.EntityFramework and Oracle.ManagedDataAccess, my app.config contains sections for the data source and connection string. It also contains the same <section> item for oracle.manageddataaccess.client that I have in my 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 is registered in the 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 contains up-to-date references to 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>

I can successfully connect with the Oracle database using Oracle.ManagedDataAccess.Client, if I create the OracleConnection object manually.

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

I have Oracle Developer Tools for Visual Studio installed. I have followed the instructions in the section in the readme that troubleshoots "Failed to find or load" errors:

The Data Source Configuration Wizard can fail with the error "Failed to find or load the registered .NET framework data provider" if some other data provider has not been cleanly uninstalled and still has an entry in the machine.config file. Specifically, if the entry for Oracle Data Provider for .NET in the machine.config.xml file in the DbProviderFactories section comes after an already uninstalled data provider, this error will occur. The fix is to edit machine.config and move the Oracle Data Provider for .NET to the first item in the DbProviderFactories section.

I have confirmed that ODP.NET, Managed Driver is the first item in the DbProviderFactories section.

Bottom Line

What do I need to do to get my model to generate properly?

Community
  • 1
  • 1
Kevin
  • 74,910
  • 12
  • 133
  • 166
  • As described in the linked question, downgrading to older versions of the Oracle packages fixed the crashing window problem. – Kevin Mar 13 '18 at 16:10

0 Answers0