Reputation: 2857
I want to use the DbProvider class to construct a generic DAL component. This will be convenient when switching between different database providers. On a machine with Oracle 2.2 installed the Oracle provider ODP.NET is not listed when trying to list up all the database providers available on the machine.
DataTable dtable = DbProviderFactories.GetFactoryClasses();
Though referencing the Oracle.DataAccess.dll and connect to Oracle using the OracleConnection class is not problem.
OracleConnection con = new OracleConnection();
What am I doing wrong here ?
EDIT: According to this page I should see an "Oracle Data Provider for .Net" in the list.
Upvotes: 1
Views: 9988
Reputation: 6580
Here is how DbProviderFactories.GetFactoryClasses works...
By default, (if you don't have an app.config), it will look in your machine.config for a section called system.data/DBProviderFactories. Basically all "registered" db provider that will be accessabile can be found in that section.
So either add that to your app.config system.data/DBProviderFactories section or to the machine.config.
something like:
<configuration>
<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>
</configuration>
And make sure your ODP.NET version support DbProviderFactories. I think you need Oracle Database 10g Release 2 to do this.
Upvotes: 3
Reputation: 19263
Executing your code I see the following row in my datatable:
OracleClient Data Provider .Net Framework Data Provider for Oracle
System.Data.OracleClient System.Data.OracleClient.OracleClientFactory,
System.Data.OracleClient, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
System.Data.OracleClient should be in your GAC as of .NET Framework 2.0
Upvotes: 0