未在 DbProviderFactories 中列出的 Oracle 数据提供程序 (ODP.NET)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1114539/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 18:35:12  来源:igfitidea点击:

Oracle data provider (ODP.NET) not listed in DbProviderFactories

c#databaseoracle

提问by Mez

I want to use the DbProvider class to construct a generic DAL component. This will be convenient when switching between different database providers. On a machine with Oracle 2.2 installed the Oracle provider ODP.NET is not listed when trying to list up all the database providers available on the machine.

我想使用 DbProvider 类来构造一个通用的 DAL 组件。这在不同的数据库提供者之间切换时会很方便。在安装了 Oracle 2.2 的机器上,尝试列出机器上所有可用的数据库提供程序时,未列出 Oracle 提供程序 ODP.NET。

   DataTable dtable = DbProviderFactories.GetFactoryClasses();

Though referencing the Oracle.DataAccess.dll and connect to Oracle using the OracleConnection class is not problem.

虽然引用 Oracle.DataAccess.dll 并使用 OracleConnection 类连接到 Oracle 没有问题。

OracleConnection con = new OracleConnection();

What am I doing wrong here ?

我在这里做错了什么?

EDIT: According to this pageI should see an "Oracle Data Provider for .Net" in the list.

编辑:根据此页面,我应该在列表中看到“Oracle Data Provider for .Net”。

回答by Jimmy Chandra

Here is how DbProviderFactories.GetFactoryClasses works...

以下是 DbProviderFactories.GetFactoryClasses 的工作原理...

By default, (if you don't have an app.config), it will look in your machine.config for a section called system.data/DBProviderFactories. Basically all "registered" db provider that will be accessabile can be found in that section.

默认情况下(如果您没有 app.config),它将在您的 machine.config 中查找名为 system.data/DBProviderFactories 的部分。基本上所有可以访问的“注册”数据库提供程序都可以在该部分找到。

So either add that to your app.config system.data/DBProviderFactories section or to the machine.config.

因此,要么将其添加到您的 app.config system.data/DBProviderFactories 部分,要么添加到 machine.config。

something like:

就像是:

<configuration>
  <system.data>
    <DbProviderFactories>
      <add name="Oracle Data Provider for .NET" invariant="Oracle.DataAccess.Client" description=".Net Framework Data Provider for Oracle" type="Oracle.DataAccess.Client.OracleClientFactory, Oracle.DataAccess, Version=10.2.0.100, Culture=neutral, PublicKeyToken=89b483f429c47342" />
    </DbProviderFactories>
  </system.data>
</configuration>

And make sure your ODP.NET version support DbProviderFactories. I think you need Oracle Database 10g Release 2 to do this.

并确保您的 ODP.NET 版本支持 DbProviderFactories。我认为您需要 Oracle Database 10g 第 2 版来执行此操作。

回答by Zyphrax

Executing your code I see the following row in my datatable:

执行您的代码,我在数据表中看到以下行:

OracleClient Data Provider .Net Framework Data Provider for Oracle
System.Data.OracleClient System.Data.OracleClient.OracleClientFactory,
System.Data.OracleClient, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089

System.Data.OracleClient should be in your GAC as of .NET Framework 2.0

从 .NET Framework 2.0 开始,System.Data.OracleClient 应该在您的 GAC 中