title: C# ExecuteReader requires an open and available Connection. The connection's current state is closed
body: <pre><code>private void comT_SelectedIndexChanged(object sender, EventArgs e)
      {
          if (comT.SelectedIndex != -1)
          {
              SqlCommand cmd = new SqlCommand(@"SELECT ISNULL(substring(MAX(tCode),3,2),'00')
              FROM Teacher
              WHERE dCode = '" + comT.SelectedValue.ToString() + "'", MUControlClass.con);
              SqlDataReader dr = cmd.ExecuteReader();
              dr.Read();  &lt;--HERE IS ERROR **"ExecuteReader requires an open and available Connection. The connection's current state is closed."**
              if (dr[0].ToString() != "00")
              {
                  int dugaar = Convert.ToInt32(dr[0]) + 1;
                  if (dugaar &gt; 9)
                  {
                      msk.Text = comT.SelectedValue.ToString() + dugaar.ToString();
                  }
                  else
                      msk.Text = comT.SelectedValue.ToString() + "0" + dugaar.ToString();
              }
              else
              {
                  msk.Text = comT.SelectedValue.ToString() + "01";
              }
              dr.Close();
          }
      }
  </code></pre>
  
  <p>ExecuteReader requires an open and available Connection. The connection's current state is closed. Error</p>