title: MySqlDataReader stops reading after about 4 minutes and returns
body: <p>I have a simple query which returns 25,026 rows:</p>
  
  <pre><code>MySqlCommand cmd = new MySqlCommand("SELECT ID FROM People", DB);
  MySqlDataReader reader = cmd.ExecuteReader();
  </code></pre>
  
  <p>(<code>ID</code> is an <code>int</code>.)  If I just do this:</p>
  
  <pre><code>int i = 0;
  while (reader.Read()) i++;
  </code></pre>
  
  <p><code>i</code> will equal 25026.  However, I need to do some processing on each ID in my loop; each iteration ends up taking somewhere in the hundreds of milliseconds.</p>
  
  <pre><code>int i = 0;
  MySqlCommand updater = new MySqlCommand("INSERT INTO OtherTable (...)", anotherConnection);
  updater.Prepare();
  while (reader.Read()) {
       int id = reader.getInt32(0);
       // do stuff, then
       updater.ExecuteNonQuery();
       i++;
  }
  </code></pre>
  
  <p>However, after about 4:15 of processing, <code>reader.Read()</code> simply returns false.  In most of my test runs, <code>i</code> equaled 14896, but it also sometimes stops at 11920.  The <code>DataReader</code> quitting after the same number of records is suspicious, and the times it stops after a different number of rows seems even stranger.</p>
  
  <p>Why is <code>reader.Read()</code> returning false when there's definitely more rows?  There are no exceptions being thrown &ndash; not even first chance exceptions.</p>
  
  <hr/>
  
  <p><b>Update:</b> I mentioned in my response to <a href="https://stackoverflow.com/questions/3350153/mysqldatareader-stops-reading-after-about-4-minutes-and-returns/3480458#3480458">Shaun's answer</a> that I was becoming convinced that <code>MySqlDataReader.Read()</code> is swallowing an exception, so I downloaded <a href="https://code.launchpad.net/~mysql-clr-team/connectornet/6.2" rel="nofollow noreferrer">Connector/Net's source code</a> (<code><a href="http://bazaar.canonical.com/" rel="nofollow noreferrer">bzr</a> branch lp:connectornet/6.2 C:/local/path</code>) and added the project to my solution.  Sure enough, after 6:15 of processing, <strong>an exception!</strong></p>
  
  <p>The call to <code><a href="http://bazaar.launchpad.net/~mysql-clr-team/connectornet/6.2/annotate/head%3A/MySql.Data/Provider/Source/datareader.cs#L930" rel="nofollow noreferrer">resultSet.NextRow()</a></code> throws a <code>MySqlException</code> with a message of "Reading from the stream has failed."  The <code>InnerException</code> is a <code>SocketException</code>:</p>
  
  <pre><code>{ Message: "An existing connection was forcibly closed by the remote host",
    ErrorCode: 10054,
    SocketErrorCode: ConnectionReset }
  </code></pre>
  
  <p>10054 means the TCP socket was aborted with a <code>RST</code> instead of the normal disconnection handshake (<code>FIN</code>, <code>FIN ACK</code>, <code>ACK</code>), which tells me something screwy is happening to the network connection.</p>
  
  <p>In my.ini, I cranked <code>interactive_timeout</code> and <code>wait_timeout</code> to 1814400 (seconds) to no avail.</p>
  
  <p>So... why is my connection getting torn down after reading for 6:15 (375 sec)?</p>
  
  <p>(Also, why is this exception getting swallowed when I use the official binary?  It <em>looks</em> like it should bubble up to my application code.)</p>