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.

Tony L.
  • 17,638
  • 8
  • 69
  • 66
theringostarrs
  • 11,940
  • 14
  • 50
  • 63
  • the same problem and resolve http://stackoverflow.com/questions/4225908/error-when-adding-a-configuration-to-app-config-file – Anton Zimm Dec 22 '12 at 14:03

4 Answers4

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!

martin
  • 1,056
  • 8
  • 6
  • 1
    This problem can also occur if you have installed ODP.net before installing the version of .NET you are using, in my case .NET4. – Fredrik C Jan 15 '14 at 09:43
  • @FredrikC: Thanks for your comment is there any command to register it again – Dhaval Patel May 26 '14 at 14:22
  • @DhavalPatel I would reinstall ODP.net but you can follow the instructions at https://community.oracle.com/thread/2127248?tstart=15 and it should work. I have not tried it myself though! – Fredrik C May 26 '14 at 19:28
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>
granadaCoder
  • 26,328
  • 10
  • 113
  • 146
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>
Tony L.
  • 17,638
  • 8
  • 69
  • 66
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.

yikekas
  • 129
  • 1
  • 5