Writing a Generic Data Access Component - Flexible Approach
Here is one more flexible approach to achieve the same. I prefer this approach to generic data access.
In response to Mahesh's article - Writing a Generic Data Access Component using ADO.NET Interfaces, here is one more flexible approach to achieve the same. I prefer this approach to generic data access.
public class DB
public static IDbConnection GetConnection()
Type cnType = Type.GetType(ConfigurationSettings.AppSettings("connectionType"));
DbConnection cn = (IDbConnection)Activator.CreateInstance(cnType);
cn.ConnectionString = ConfigurationSettings.AppSettings("connectionString");
} Any application which uses above class must provide following entries in its .config file.
<add key="connectionType" value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<add key="connectionString" value="server=your_host;database=your_db;uid=your_uid;pwd=your_pwd" />
This approach is flexible because no recompilation is needed if a new provider is to be utilized.