.NET 2 has new factories that makes it easier to write data-programs independent of the databsae.
With .NET 1.0, we could program independent of the database using interfaces:
IDbConnection connection = new SqlConnection(connectionString);
IDbCommand command = connection.CreateCommand();
command.CommandText = "select * from customers";
connection.Open();
IDataReader reader = command.ExecuteReader();
while (reader.Read())
{
//...
The connection object can also be created with the Activator class - to make it independent of the database. What about creating a SqlDataAdapter? This needs to be done similar to the connection. A custom factory class is very useful with 1.0.
.NET 2.0 offers database-independent factory DBProviderFactory:
DbProviderFactory provider = DbProviderFactories.GetFactory ("System.Data.SqlClient");
DbConnection connection = provider.CreateConnection ();
DbDataAdapter adapter = provider.CreateDataAdapter ();
The available providers can be found in the configuration file.
Christian