Saturday, February 13, 2010

DbProviderFactory Class

If you know you're going to need an SqlConnection always and forever in your code, there's no advantage at all. But what if you want your code to be able to use either an SqlConnection, or an OracleConnection? Then you want to use a DBProviderFactory to let the code determine which connection to use, rather than hardcoding in some sort of switching logic.

Reference: http://msdn2.microsoft.com/en-us/library/wda6c36e.aspx

The System.Data.Common namespace provides classes for creating DbProviderFactory instances to work with specific databases. When you create a DbProviderFactory instance, passing it information about the provider along with the connection string, the instance can determine the correct strongly-typed object to return based on the information it has been provided. This lets you write code that is not dependent on the data provider and lets you choose the provider at runtime.

No comments:

Post a Comment