DbProviderFactories for .NET Error
Asked Answered
P

4

10

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.

Pyrogenic answered 15/1, 2010 at 3:30 Comment(1)
the same problem and resolve #4226408Equilibrium
D
8

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!

Deflocculate answered 16/3, 2010 at 10:37 Comment(3)
This problem can also occur if you have installed ODP.net before installing the version of .NET you are using, in my case .NET4.Crowning
@FredrikC: Thanks for your comment is there any command to register it againBrachio
@DhavalPatel I would reinstall ODP.net but you can follow the instructions at community.oracle.com/thread/2127248?tstart=15 and it should work. I have not tried it myself though!Crowning
C
6

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>
Checkerberry answered 22/1, 2013 at 19:14 Comment(0)
B
2

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>
Breadnut answered 24/9, 2015 at 21:18 Comment(0)
O
1

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.

Oldie answered 30/9, 2017 at 18:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.