You are here

Blog Archive

DbProviderFactory GetConnection

With the new ADO.NET 2.0 DbProviderFactory and DbProviderFactories classes, you can change the database provider at runtime.  The DbProviderFactories class is use to create a factory object, which in turn is use to create the appropriate provider objects (connection, command, dataadapter, etc).  Here's an example that returns a DbConnection object based on the name of the connection string in the Web.config file.

/// <summary>

/// Create generic database connection object using new DbProviderFactories class.