开发者

DbProviderFactories for .NET Error

开发者 https://www.devze.com 2022-12-17 13:03 出处:网络
I am having trouble getting the ODP.NEt library to work with the .NET DBProviderFactories. I am getting the following error with this code:

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开发者_JAVA技巧>
    <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.


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!


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>


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>


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号