title: MySQL - Multiple result sets
body: <p>I'm using .NET Connector to connect to MySQL.
  In my application there are few threads using the same connection, so if a MySQLDataReader is not closed yet and some thread is trying execute a query it gives that error:</p>
  
  <blockquote>
    <p>There is already an open DataReader associated with this Connection which must be closed first.</p>
  </blockquote>
  
  <p>Will there ever be support in MySQL for multiple result sets or however it's called?</p>
  
  <p>My database management class:</p>
  
  <pre><code>public class DatabaseConnection
  {
      private MySqlConnection conn;
  
      public void Connect(string server, string user, string password, string database, int port = 3306)
      {
          string connStr = String.Format("server={0};user={1};database={2};port={3};password={4};charset=utf8",
              server, user, database, port, password);
          conn = new MySqlConnection(connStr);
          conn.Open();
      }
  
      private MySqlCommand PrepareQuery(string query, object[] args)
      {
          MySqlCommand cmd = new MySqlCommand();
          cmd.Connection = conn;
          for (int i = 0; i &lt; args.Length; i++)
          {
              string param = "{" + i + "}";
              string paramName = "@DBVar_" + i;
              query = query.Replace(param, paramName);
              cmd.Parameters.AddWithValue(paramName, args[i]);
          }
          cmd.CommandText = query;
          return cmd;
      }
  
      public List&lt;Dictionary&lt;string, object&gt;&gt; Query(string query, params object[] args)
      {
          MySqlCommand cmd = PrepareQuery(query, args);
          MySqlDataReader reader = cmd.ExecuteReader();
          List&lt;Dictionary&lt;string, object&gt;&gt; rows = new List&lt;Dictionary&lt;string, object&gt;&gt;();
          while (reader.Read())
          {
              Dictionary&lt;string, object&gt; row = new Dictionary&lt;string, object&gt;();
              for (int i = 0; i &lt; reader.FieldCount; i++)
              {
                  row.Add(reader.GetName(i), reader.GetValue(i));
              }
              rows.Add(row);
          }
          reader.Close();
          return rows;
      }
  
      public object ScalarQuery(string query, params object[] args)
      {
          MySqlCommand cmd = PrepareQuery(query, args);
          return cmd.ExecuteScalar();
      }
  
      public void Execute(string query, params object[] args)
      {
          MySqlCommand cmd = PrepareQuery(query, args);
          cmd.ExecuteNonQuery();
      }
  
      public void Close()
      {
          conn.Close();
      }
  }
  </code></pre>
  
  <p>An example of how I use this:</p>
  
  <pre><code>DatabaseConnection Conn = new DatabaseConnection();
  Conn.Connect("localhost", "root", "", "foogle");
  var rows = conn.Query("SELECT * FROM `posts` WHERE `id` = {0}", postID);
  foreach (var row in rows)
  {
     Console.WriteLine(row["title"]); // Writes the post's title (example)
  }
  </code></pre>