DbProviderFactories for .NET Error

I had a problem getting the ODP.NEt library to work with .NET DBProviderFactories. I get the following error with this code:

_DBFactory = DbProviderFactories.GetFactory(providerName); 

An error occurred while creating the configuration section handler for system.data: The InvariantName column is limited to a unique one. The value "Oracle.DataAccess.Client" is already present.

with this provider name: Oracle.DataAccess.Client

And the following entry in the web.config file:

  <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 configured twice anywhere.

+7
web-config
source share
4 answers

If you installed ODP.net (for example, using the oracle universal installer, unlike xcopy), you will find the same DbProviderFactories / add in machine.config.

So adding it to your web.config adds it a second time - so duplicate Oracle.DataAccess.Client!

+6
source share

Can you do 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> 
+5
source share

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

You can also just remove this class before re-adding it by adding this line:

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

This is what the whole <system.data> would look like:

  <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 and server environments do not have the appropriate configuration files, such as machine.config.

Another thing you could do is simply remove it from your web.config together, assuming the parameter in your machine.config will work. However, I would test this on both your development machine and your servers. In my case, he worked on one and not the other, because the machine.config files did not match. To solve this problem, I added this parameter to the machine.config file on the server without <remove invariant="Oracle.ManagedDataAccess.Client" /> , for example:

  <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> 
+1
source share

Most likely, the DbProviderFactories section of the machine configuration file crashed. Check to see if there is an extra Oracle.DataAccess.Client line that still remains after uninstalling the oracle client.

+1
source share

All Articles