Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DbProviderFactories for .NET Error

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.

like image 747
theringostarrs Avatar asked Jan 15 '10 03:01

theringostarrs


4 Answers

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!

like image 156
martin Avatar answered Nov 17 '22 20:11

martin


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>
like image 38
Tony L. Avatar answered Nov 17 '22 20:11

Tony L.


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>
like image 26
granadaCoder Avatar answered Nov 17 '22 22:11

granadaCoder


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.

like image 1
yikekas Avatar answered Nov 17 '22 21:11

yikekas