title: C# Invalid attempt to call Read when reader is closed
body: <p>I am having Invalid attempt to call Read when reader is closed error when I am doing 3 tier project in C# language.
  What I am trying to do is retrieve address data column by joining two tables together and display in a drop down list.
  Here is my data access layer:</p>
  <pre><code>public List&lt;Distribution&gt; getDistributionAll()
  {
      List&lt;Distribution&gt; distributionAll = new List&lt;Distribution&gt;();
      string address;
      SqlDataReader dr = FoodBankDB.executeReader(&quot;SELECT b.addressLineOne FROM dbo.Beneficiaries b INNER JOIN dbo.Distributions d ON d.beneficiary = b.id&quot;);
  
      while (dr.Read())
      {
          address = dr[&quot;addressLineOne&quot;].ToString();
          distributionAll.Add(new Distribution(address));
      }
  
      return distributionAll;
  }
  </code></pre>
  <p>And this is my FoodBankDB class:</p>
  <pre><code>public class FoodBankDB
  {
      public static string connectionString = Properties.Settings.Default.connectionString;
      public static SqlDataReader executeReader(string query)
      {
          SqlDataReader result = null;
          System.Diagnostics.Debug.WriteLine(&quot;FoodBankDB executeReader: &quot; + query);
          SqlConnection connection = new SqlConnection(connectionString);
          SqlCommand command = new SqlCommand(query, connection);
          connection.Open();
          result = command.ExecuteReader();
          connection.Close();
          return result;
      }
  }
  </code></pre>
  <p>I separated the these into two class so that whenever my connection string is changed, I can amend the whole project easily by changing the FoodBankDB class.</p>
  <p>And this is my business logic layer:</p>
  <pre><code>public List&lt;Distribution&gt; getAllScheduledDistribution()
  {
      List&lt;Distribution&gt; allDistribution = new List&lt;Distribution&gt;();
      Distribution distributionDAL = new Distribution();
      allDistribution = distributionDAL.getDistributionAll();
      return allDistribution;
  }
  </code></pre>
  <p>And last but not least, my presentation layer:</p>
  <pre><code>List&lt;Distribution&gt; scheduledList = new List&lt;Distribution&gt;();
  scheduledList = packBLL.getAllScheduledDistribution();
  ddlScheduleList.DataSource = scheduledList;
  ddlScheduleList.DataTextField = &quot;address&quot;;
  ddlScheduleList.DataValueField = &quot;address&quot;;
  ddlScheduleList.DataBind();
  </code></pre>
  <p>It was working well if I didn't split the data access layer and connection string class. Does anybody know how to solve this error?</p>
  <p>Thanks in advance.</p>
  <p><em><strong>Updated portion</strong></em></p>
  <pre><code>public static string GetConnectionString()
  {
      return connectionString;
  }
  </code></pre>