.NET 错误的 DbProviderFactories

发布于 2024-08-17 22:09:45 字数 782 浏览 6 评论 0原文

我在让 ODP.NEt 库与 .NET DBProviderFactories 一起使用时遇到问题。我使用此代码收到以下错误:

_DBFactory = DbProviderFactories.GetFactory(providerName);

为 system.data 创建配置节处理程序时发生错误:列“InvariantName”被限制为唯一。值“Oracle.DataAccess.Client”已存在。

使用此提供程序名称:Oracle.DataAccess.Client

以及 web.config 中的以下条目:

  <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>

有谁知道出了什么问题?我不认为我在任何地方都设置了两次。

I am having trouble getting the ODP.NEt library to work with the .NET DBProviderFactories. I am getting the following error with this code:

_DBFactory = DbProviderFactories.GetFactory(providerName);

An error occurred creating the configuration section handler for system.data: Column 'InvariantName' is constrained to be unique. Value 'Oracle.DataAccess.Client' is already present.

with this providerName: Oracle.DataAccess.Client

And the following entry in the web.config:

  <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>

Does anyone know what is wrong? I don't think I have it set up twice anywhere.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

旧时浪漫 2024-08-24 22:09:45

如果您安装了 ODP.net(例如,使用 oracle 通用安装程序,而不是 xcopy),您将在 machine.config 中找到相同的 DbProviderFactories/add。

因此,将其添加到您的 web.config 中就是第二次添加它 - 因此,复制 Oracle.DataAccess.Client!

If you installed ODP.net (eg using the oracle universal installer, as opposed to xcopy), you'll find the same DbProviderFactories/add in machine.config.

So adding it in your web.config is adding it a second time - so, duplicate Oracle.DataAccess.Client!

來不及說愛妳 2024-08-24 22:09:45

下面的事情你能做到吗? (注意“清楚”)

  <system.data>
    <DbProviderFactories>

      <clear />

      <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>

Can you do the below? (Note the "clear")

  <system.data>
    <DbProviderFactories>

      <clear />

      <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>
土豪 2024-08-24 22:09:45

应该注意的是, 将清除所有您可能不希望执行的DbProviderFactories,具体取决于您的情况。

您还可以在重新添加该类之前通过添加以下行来删除该类:

以下是整个 < system.data> 看起来:

  <system.data>
    <DbProviderFactories>
      <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>
  </system.data>

如果您的本地计算机和服务器环境没有匹配的配置文件(例如 machine.config),这可能很有用。

您可以做的另一件事就是将其从您的 web.config 中一起删除,假设您的 machine.config 中的设置可以工作。但是,我会在您的开发计算机和服务器上对此进行测试。就我而言,它适用于其中一个,但不适用于另一个,因为 machine.config 文件不匹配。为了解决这个问题,我将相同的设置添加到服务器上的 machine.config 中,而没有 ,如下所示:

  <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.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
    </DbProviderFactories>
  </system.data>

It should be noted that <clear /> will clear all DbProviderFactories which you may not want to do, depending on your situation.

You could also just remove that class right before you re-add it by adding this line:

<remove invariant="Oracle.ManagedDataAccess.Client" />

Here's how the whole <system.data> would look:

  <system.data>
    <DbProviderFactories>
      <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>
  </system.data>

This can be useful if your local machine and server environments don't have matching config files such as machine.config.

The other thing you could do is just remove it from your web.config all together assuming the setting in your machine.config will work. However, I would test this on both you development machine and your servers. In my case, it worked on one but not the other because the machine.config files didn't match. To resolve, I added this same setting to the machine.config on the server without the <remove invariant="Oracle.ManagedDataAccess.Client" /> like so:

  <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.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
    </DbProviderFactories>
  </system.data>
滴情不沾 2024-08-24 22:09:45

最有可能的是机器配置文件 DbProviderFactories 部分崩溃了。
检查是否有多余的Oracle.DataAccess.Client行,卸载oracle客户端后仍然存在。

Most probably the machine config file DbProviderFactories section crashed.
Check if there is extra Oracle.DataAccess.Client line, which still remains after uninstall oracle client.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文