title: ExecuteNonQuery requires an open and available Connection. The connection's current state is closed
body: <p><strong>ExecuteNonQuery requires an open and available Connection. The connection's current state is closed.</strong></p>
  
  <p>What am I doing wrong here?  I'm assuming you can reuse the connection?</p>
  
  <p>Thanks for any help!</p>
  
  <pre><code>using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ToString()))
  {
      cn.Open();
  
      // If we are reverting to an old type
      if (pageAction == "revert")
      {
          debug.Text = "FLAG 1";
  
          // Get the revert ID
          int revertingID = int.Parse(Request.QueryString["revID"]);
          bool rowsReturned = false;
  
          debug.Text = "FLAG 2 - " + revertingID.ToString();
  
          // Set all to 0
          using (SqlCommand cmd = new SqlCommand("SELECT ID FROM tblSiteSettings WHERE ID = " + revertingID, cn))
          {
              // If it exists
              SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
              if (rdr.Read())
              {
                  rowsReturned = true;
              }
              rdr.Close();
          }
  
          debug.Text = "FLAG 3 - " + rowsReturned.ToString();
  
          // Set new active and reset others
          if (rowsReturned == true)
          {
              using (SqlCommand cmd = new SqlCommand("UPDATE tblSiteSettings SET isActive = 1 WHERE ID = " + revertingID, cn))
              {
                  cmd.ExecuteNonQuery();
              }
              using (SqlCommand cmd = new SqlCommand("UPDATE tblSiteSettings SET isActive = 0 WHERE ID &lt;&gt; " + revertingID, cn))
              {
                  cmd.ExecuteNonQuery();
              }
          }
          //debug.Text = "FLAG 4 - ";
      }
  </code></pre>