ADO.NET提供程序“Oracle.ManagedDataAccess.Client”未在计算机或应用程序配置文件中注册,或者无法加载

u0sqgete  于 2023-08-03  发布在  Oracle
关注(0)|答案(4)|浏览(261)

我使用的是.NET4.5.1MVC5EF6,以及Oracle.ManagedDataAccess 4.121.1.0Oracle.ManagedDataAccess.EntityFramework 6.121.2.0
我能够从现有的数据库中生成模型(其中一部分是逐表添加的),应用程序构建得很好。
然而,当我尝试运行测试查询,看看它是否可以得到的数据

public ActionResult Cancellations()
    {
        var factoryClasses = System.Data.Common.DbProviderFactories.GetFactoryClasses();
        using (var db = new Entities())
        {
            var cancelationStatuses = new[] {3, 7, 9};
           var result = db.TRANSACTIONDETAIL.Where(o => cancelationStatuses.Contains(o.TRANSACTIONSTATUSID));
           return View(result);
        }
    }

字符串
它失败(在var result = ...上),使用Unable to find the requested .Net Framework Data Provider. It may not be installed.
当尝试查找DbProviderFactories时,在collection(var factoryClasses =)中确实没有任何内容。
但是,I do have installed 12c 4 (ODTwithODAC121024)和11g(ODTwithODAC1120320_32bit)已重新启动计算机。
数据库在11g上运行,我可以使用PL/SQL developer

访问它
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>
.....
<add name="OracleDbContext" providerName="Oracle.ManagedDataAccess.Client" connectionString="User Id=oracle_user;Password=oracle_user_password;Data Source=oracle" />
 <add name="Entities" connectionString="metadata=res://*/OracleDb.csdl|res://*/OracleDb.ssdl|res://*/OracleDb.msl;provider=Oracle.ManagedDataAccess.Client;provider connection string='data source=******" providerName="System.Data.EntityClient" />           </connectionStrings>
......
<system.data>
<DbProviderFactories>
  <!-- Remove in case this is already defined in machine.config -->
  <add name="Oracle Data Provider for .NET" invariant="Oracle.ManagedDataAccess.Client" description="Oracle Data Provider for .NET" type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
  <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>


我假设它失败是因为Oracle没有在DbProviderFactories或其他地方注册

如何在DbProviderFactories中注册Oracle?如果不是这样,我的设置有什么问题?

flvlnr44

flvlnr441#

我通过从NuGet添加ODP.NET(Oracle.ManagedDataAccess.EntityFramework12c)解决了这个问题。VS2015使用EF 6.2.0。

7rtdyuoh

7rtdyuoh2#

我刚刚通过安装Oracle Developer工具for Visual Studio 2013(我安装的VS版本)ODTforVS2013_121025.exe解决了这个错误

jecbmhm3

jecbmhm33#

我在更新Visual Studio 2017时遇到了这个错误。这个错误可以通过重新安装VS 2017的ODT来解决:
1)关闭Visual Studio。
2)从控制面板卸载现有的Oracle Developer Tools for Visual Studio 2017。
3)从以下链接安装最新版本(ODTforVS2017_122011.exe):
http://www.oracle.com/technetwork/topics/dotnet/downloads/odacmsidownloadvs2017-3806459.html
4)打开visual studio并生成解决方案。现在不应生成错误。

x7rlezfr

x7rlezfr4#

想明白了
在我的machine.config已经有

<add name="Oracle Data Provider for .NET" invariant="Oracle.ManagedDataAccess.Client" description="Oracle Data Provider for .NET" type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />

字符串
然后它在我的web.config中重复,这将默默地失败给予出任何提供程序。所以取出后:

<add name="Oracle Data Provider for .NET" invariant="Oracle.ManagedDataAccess.Client" description="Oracle Data Provider for .NET" type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
  <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" />


我让它跑起来了。

相关问题