title: Invalid attempt to Read when reader is closed
body: <p>I have a common database class for my application  and in that class i have a function </p>
  
  <pre><code>public MySqlDataReader getRecord(string query)
          {
              MySqlDataReader reader;
              using (var connection = new MySqlConnection(connectionString))
              {
                  connection.Open();
                  using (var cmd = new MySqlCommand(query, connection))
                  {
  
                      reader = cmd.ExecuteReader();
                      return reader;
  
                  }
              }
  
              return null;
          }
  </code></pre>
  
  <p>and on my code behind pages I use</p>
  
  <pre><code>String sql = "SELECT * FROM `table`";
  MySqlDataReader dr = objDB.getRecord(sql);
  if (dr.Read())
  {
     // some code goes hear
  } 
  </code></pre>
  
  <p>and I am having error as <strong>Invalid attempt to Read when reader is closed.</strong> </p>
  
  <p>I know access the reader after the database connection is closed is not possible 
  bot <strong>I am looking for a work around</strong> in which I <strong>need not to change in the codebehind</strong> </p>
  
  <p><strong>EDIT: I WILL LIKE THE SOLUTION IN WHICH THE READER IS ASSIGNED TO OTHER OBJECT (SIMILAR TO READER ) AND THEN RETURN THAT OBJECT</strong> so i need not to change in all the application pages </p>