title: Attempted to read past end of the stream error in MySQL
body: <p>I'm running into a problem with MySQL where I have the following error.</p>
  
  <pre><code>MySqlClient.MySqlException: Fatal error encountered during command execution. ---&gt; 
  MySql.Data.MySqlClient.MySqlException: Fatal error encountered attempting to read the resultset. ---&gt; 
  MySql.Data.MySqlClient.MySqlException: Reading from the stream has failed. ---&gt; 
  System.IO.EndOfStreamException: Attempted to read past the end of the stream.
  </code></pre>
  
  <p>This error occurs when I have this running overnight. And it happens infrequently, so it is hard to track down WHY it's happening. I am using .NET 3.5 with MySQLConnector 6.2.4.0.</p>
  
  <p>I am running it using the following code.</p>
  
  <pre><code>        public DataSet Read(String query, List&lt;KeyValuePair&lt;String, object&gt;&gt; parameters)
      {
          MySqlDataAdapter adapter = null;
          DataSet returnVal = null;
          if (query != null &amp;&amp; query.Length &gt; 0)
          {
              try
              {
                  returnVal = new DataSet();
                  if (connection.State != ConnectionState.Open)
                  {
                      connection.Open();
                  }
                  query = SQLHelper.formatSQL(query);
                  MySqlCommand command = buildCommand(connection, query, parameters);
  
                  Stopwatch stopwatch = new Stopwatch();
  
                  command.CommandTimeout = 120;
                  adapter = new MySqlDataAdapter(command);
                  log.Debug(adapter.SelectCommand.CommandText);
                  stopwatch.Start();
                  adapter.Fill(returnVal);
                  stopwatch.Stop();
                  if (stopwatch.ElapsedMilliseconds &lt; 150)
                  {
                      log.Debug(stopwatch.ElapsedMilliseconds + "ms to run query");
                  }
                  else
                  {
                      StringBuilder sb = new StringBuilder("");
                      if (parameters != null)
                      {
                          foreach (KeyValuePair&lt;String, object&gt; kvp in parameters)
                          {
                              sb.Append(kvp.Key);
                              sb.Append(" = ");
                              if (kvp.Value != null)
                              {
                                  sb.Append(kvp.Value.ToString());
                              }
                              else
                              {
                                  sb.Append("NULL");
                              }
                              sb.Append(", ");
                          }
                      }
                      log.Warn(stopwatch.ElapsedMilliseconds + "ms to run query: " + adapter.SelectCommand.CommandText + "Values: " + sb.ToString());
                  }
              }
              catch (MySqlException msqlex)
              {
                  log.Error(msqlex);
                  returnVal = null;
                  MessageBox.Show(query + "\r\n" + msqlex.ToString());
              }
              finally
              {
              }
          }
          else
          {
              log.Error("Query is empty. Returning null");
          }
          return returnVal;
      }
  </code></pre>
  
  <p>As you can see, I am not manually attempting to read anything >&lt; I'm doing an <code>adapter.fill(x)</code>, so I have no control over reading past the end of the stream.</p>
  
  <p>Why may be this happening? </p>
  
  <p>Please let me know if you need any more details.</p>