title: ExecuteReader Connection error when Filling the DataAdapter with DataSet
body: <p>There is a MVC Web Application which has one module implemented with ADO.NET.
  The Controller Code is below:</p>
  
  <pre><code>private List&lt;CustomTabModel&gt; GenerateReports(ReportModel oViewModel)
  {
      List&lt;CentralDbCase&gt; Cases = AppController.Instance.Prov.Cases(a, b, c, InitiativeTypes(submissionYear), includedDataSource, namePrefix, out message);
  
     //other code
  
      return DoWork(Cases);
  }       
  private List&lt;CustomTabModel&gt; DoWork(List&lt;CentralDbCase&gt; Cases)
  {
     //other code
  }
  </code></pre>
  
  <p>When attempting to connect to SQL database, I am getting below error when two or more people connect to the application simultaneously:</p>
  
  <p><strong>ExecuteReader requires an open and available Connection. The connection's current state is open.</strong></p>
  
  <p>Below are following Business Classes, I am using for this module:
  1 Provider.cs (inside BusinessLayer Folder)</p>
  
  <pre><code>public List&lt;CentralDbCase&gt; Cases(string a, int b, List&lt;KeyValuePair&lt;string, string&gt;&gt; c, List&lt;string&gt; SelectedTypes, string includedDataSource, string NamePrefix, out string message)
          {            
              List&lt;CentralDbCase&gt; theList = new List&lt;CentralDbCase&gt;();
  
              string sql = (AppController.Instance.DbConnection is System.Data.SqlClient.SqlConnection) ? ListCaseSqlEx(a, b, c) : ListCaseSql(a, b, c);
  
              IDbCommand cmd = DbHelper.NewCommandForConnection(AppController.Instance.DbConnection, sql);
              IDbDataAdapter da = DbHelper.NewDataAdapterForConnection(AppController.Instance.DbConnection);
              da.SelectCommand = cmd;
  
              DataSet ds = new DataSet();
              ds.CaseSensitive = true;
  
              da.Fill(ds);  //--getting error here--
  
              //other line of code
  
              return theList;
          }
  </code></pre>
  
  <p>2 ICentralDbProvider.cs (inside BusinessLayer Folder)</p>
  
  <pre><code>namespace PJ.Business
  {
      public interface ICentralDbProvider
      {
          List&lt;CentralDbCase&gt; Cases(string a, int b, List&lt;KeyValuePair&lt;string,string&gt;&gt; c, 
              List&lt;string&gt; SelectedTypes, string includedDataSource, string NamePrefix, out string message);
  
          Dictionary&lt;string, string&gt; ListNames(int submissionYear);
  
          VariableInfo[] VariableTypes { get; }
  
          DataTable GetDataTable(int submissionYear, string scenario, TableName tableName, string tablePrefix, string whereClause, string includedDataSource);        
      }
  }
  </code></pre>
  
  <p>3 AppController.cs (inside BusinessLayer Folder)</p>
  
  <pre><code>namespace PJ.Business
  {
      public class AppController
      {
          IDbConnection dbConnection;
          ICentralDbProvider cdbProv;
  
          public static AppController Instance
          {
              get
              {
                  if (_appController == null)
                  {
                      _appController = new AppController();
                  }
                  return _appController;
              }
          }
  
          public void InitConnection()
          {
              string connString = ConfigurationManager.ConnectionStrings["ABC_Connection"].ConnectionString;
              string provider = ConfigurationManager.ConnectionStrings["ABC_Connection"].ProviderName;
  
              if (provider == EnumHelper.GetDescription(Provider.SQL))
              {
                  dbConnection = new System.Data.SqlClient.SqlConnection(connString);                
              }
              else if (provider == EnumHelper.GetDescription(Provider.Oracle))
              {
                  dbConnection = new System.Data.OracleClient.OracleConnection(connString);
              }
              else
              {
                  throw new Exception("Invalid Connection");
              }
          }
  
          public IDbConnection DbConnection
          {
              get { return dbConnection; }
              set { dbConnection = value; }
          }
  
          public ICentralDbProvider Prov
          {
              get { return cdbProv; }
              set { cdbProv = value; }
          }
  
      }
  }
  </code></pre>
  
  <p>4 DbHelper.cs (inside BusinessLayer Folder)</p>
  
  <pre><code>namespace PJ.Business
  {
      internal static class DbHelper
      {
          public static IDbCommand NewCommandForConnection(IDbConnection conn, string commandText)
          {
              IDbCommand cmd = NewCommandForConnection(conn);
              cmd.CommandText = commandText;
              return cmd;
          }
  
          public static IDbCommand NewCommandForConnection(IDbConnection conn)
          {
              IDbCommand cmd;
              if (conn is OracleConnection)
              {
                  cmd = new OracleCommand();
              }
              else if (conn is SqlConnection)
              {
                  cmd = new SqlCommand();
              }
              else
              {
                  throw new Exception("Incorrect Connection class currently in use.");
              }
              cmd.Connection = conn;
              return cmd;
          }
  
          public static IDbDataAdapter NewDataAdapterForConnection(IDbConnection conn)
          {
              IDbDataAdapter da;
              if (conn is OracleConnection)
              {
                  da = new OracleDataAdapter();
              }
              else if (conn is SqlConnection)
              {
                  da = new SqlDataAdapter();
              }
              else
              {
                  throw new Exception("Incorrect Connection class currently in use.");
              }
  
              return da;
          }
      }
  }
  </code></pre>
  
  <p>NOTE: This module is using Singelton Pattern. Kindly let me know what is wrong in my code.
  Thanks in advance</p>
  
  <p>EDIT: Stack Trace</p>
  
  <blockquote>
    <p>System.Data.SqlClient.SqlConnection.GetOpenConnection(String method)
    System.Data.SqlClient.SqlConnection.ValidateConnectionForExecute(String
    method, SqlCommand command)
    System.Data.SqlClient.SqlCommand.ValidateCommand(String method,
    Boolean async)
    System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior
    cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String
    method, TaskCompletionSource`1 completion, Int32 timeout, Task&amp; task,
    Boolean asyncWrite)
    System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior
    cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String
    method) System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
    behavior, String method)
    System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior
    behavior)
    System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior
    behavior) System.Data.Common.DbDataAdapter.FillInternal(DataSet
    dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords,
    String srcTable, IDbCommand command, CommandBehavior behavior)
    System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32
    startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
    CommandBehavior behavior)
    System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
    PJ.Business.Provider.Cases(string a, int b, List> c, List SelectedTypes, string includedDataSource,
    string namePrefix, out string message)  in
    c:\Temp\PJ.Business\Provider.cs:line 952
    PJ.WebClient.Areas.Tool.Controllers.ReportController.GenerateReports(ReportModel
    oViewModel) in
    c:\Temp\PJ.WebClient\Areas\Tool\Controllers\ReportController.cs:line
    213 at
    PJ.WebClient.Areas.Tool.Controllers.ReportController.Index(ReportModel
    m) in
    c:\Temp\PJ.WebClient\Areas\Tool\Controllers\ReportController.cs:line
    154</p>
  </blockquote>