title: How to Create a Data Access Layer in ASP.Net which must be generic?
body: <p>I have looked several sites CodeProject,CSharpCorner,MSDN,CSharpPearls etc including one StackOverflow link:-</p>
  
  <p><a href="https://stackoverflow.com/questions/8714345/how-to-create-single-data-access-layer-to-access-two-different-data-source-in-as">how to create single Data Access Layer to access two different data source in asp.net</a></p>
  
  <p>But I was dissatisfied with the answer.</p>
  
  <p>I want to create a DAL for my website in ASP.net C#, where I am using Web.Config to get ConnectionString. But the thing is suppose today Im connecting to SQLSERVER, my DAL is capable to connect to SQLSERVER. But suppose in future Im adding one more connectionString and now Connecting to SQLSERVER with one connection string and MYSQL with another, My DAL must be capable to connect to all type of database without problem. </p>
  
  <p>What I did till now is for SQLServer which is working for SQLServer but I want this to be generic and working for OLEDB,MYSQL, SQLCLIENT, (BIGTABLE &amp; CASANDRA IF POSSIBLE) and all other providers.</p>
  
  <p>Here is my what i tried till now :-</p>
  
  <pre><code>namespace MyDAL
  {
  namespace DB
  {
      using System;
      using System.Configuration;
      using System.Data;
      using System.Data.SqlClient;
      /// &lt;summary&gt;
      /// BaseDataManager is used to connect to database
      /// &lt;/summary&gt;
      [Serializable()]
      public class BaseDataManager : IDisposable
      {
          private bool _disposedValue = false;
          private SqlConnection _connectionObject = null;
          private SqlCommand _commandObject = null;
          public BaseDataManager()
          { }
          /// &lt;summary&gt;
          /// Provide ConnectionString
          /// &lt;/summary&gt;
          public BaseDataManager(string connectionString)
          {
              this.SqlConnectionString = connectionString;
          }
  
          /// &lt;summary&gt;
          /// if config is true provide connectionstring name in Web.config
          /// else if config is false provide connectionstring rather than providing                     
          ///name
          /// &lt;/summary&gt;
          public BaseDataManager(String connectionString_Name, Boolean config)
          {
              if (config == true)
              {
                  this.SqlConnectionString = ConfigurationManager.ConnectionStrings[connectionString_Name].ConnectionString;
              }
              else if (config == false)
              {
                  this.SqlConnectionString = connectionString_Name;
              }
              else
              {
                  Console.Out.WriteLine("Error in Connection String, Check Web.Config ");
              }
          }
          /// &lt;summary&gt;
          /// Provide data source=; as connection string, username and password of
          /// database 
          /// &lt;/summary&gt;
          public BaseDataManager(string DataSource, string InitialCatalog, bool IntegratedSecurity)
          {
              if (IntegratedSecurity == true)
              {
                  this.SqlConnectionString += "Data Source=" + DataSource + "InitialCatalog=" + InitialCatalog + ";Integrated Security=" + IntegratedSecurity;
              }
          }
  
          /// &lt;summary&gt;
          /// Provide data source=; as connection string, username and password of
          /// database 
          /// &lt;/summary&gt;
          public BaseDataManager(string DataSource,string InitialCatalog, string username, string password)
          {
              this.SqlConnectionString += "Data Source="+DataSource+"InitialCatalog="+InitialCatalog+";User ID=" + username + ";Password=" + password;
          }
  
          public string SqlConnectionString
          {
              get;
              set;
          }
  
          public virtual SqlConnection connection
          {
              get
              {
                  if (_connectionObject == null &amp;&amp; !String.IsNullOrEmpty (this.SqlConnectionString))
                      _connectionObject = new SqlConnection (this.SqlConnectionString);
                  return _connectionObject;
              }
              set
              {
                  _connectionObject = value;
              }
          }
  
          public virtual SqlCommand command
          {
              get
              {
                  if (_commandObject == null)
                      _commandObject = new SqlCommand();
                  return _commandObject;
              }
              set
              {
                  _commandObject = value;
              }
          }
  
          public SqlConnection getOpenConnection()
          {
              if (connection.State == ConnectionState.Closed)
              {
                  connection.Open();
              }
              return connection;
          }
  
          public SqlCommand getCommand()
          {
              return command;
          }
  
          protected virtual void Dispose(bool disposing)
          {
              if (!_disposedValue)
              {
                  if (disposing)
                  {
  
  
     //-------------------------------------------------------------------------
                      // Close the connection object prior to setting it to nothing
  
  
     //----------------------------------------------------------------------
                      if (_connectionObject != null)
                      {
                          _connectionObject.Close();
                          _connectionObject.Dispose();
                      }
                      if (_commandObject != null)
                      {
                          _commandObject.Cancel();
                          _commandObject.Dispose();
                      }
                  }
  
                  _disposedValue = true;
              }
          }
          public void Dispose()
          {
              Dispose(true);
              GC.SuppressFinalize(this);
      GC.Collect();
          }
  
          ~BaseDataManager()
          {
              Dispose(false);
          }
  
      }
   }
   }
  </code></pre>
  
  <p>Please Help Me..</p>