I have a simple query that returns 25,026 rows:
MySqlCommand cmd = new MySqlCommand("SELECT ID FROM People", DB); MySqlDataReader reader = cmd.ExecuteReader();
( ID is int .) If I just do this:
int i = 0; while (reader.Read()) i++;
i will be equal to 25026. However, I need to do some processing for each ID in my loop; each iteration ends up happening somewhere in the hundreds of milliseconds.
int i = 0; MySqlCommand updater = new MySqlCommand("INSERT INTO OtherTable (...)", anotherConnection); updater.Prepare(); while (reader.Read()) { int id = reader.getInt32(0);
However, after approximately 4:15 of processing, reader.Read() simply returns false. In most of my test runs, i was 14896, but it also sometimes stops at 11920. A DataReader crash after the same number of records is suspicious, and the times it stops after a different number of rows seem even weirder.
Why reader.Read() return false when there are definitely more lines? Throws no exceptions - not even the first random exceptions.
Update: I mentioned in Shaun's answer that I made sure MySqlDataReader.Read() swallowing an exception, so I downloaded the Connector Source Code / Net ( bzr branch lp:connectornet/6.2 C:/local/path ) and added the project to my solution . Of course, after 6:15 a processing exception!
Calling resultSet.NextRow() throws a MySqlException message with the message "Read from stream failed." InnerException is a SocketException :
{ Message: "An existing connection was forcibly closed by the remote host", ErrorCode: 10054, SocketErrorCode: ConnectionReset }
10054 means that the TCP socket was interrupted with RST instead of the usual disconnect ( FIN , FIN ACK , ACK ), which tells me something is happening with the network connection.
In my.ini, I clicked interactive_timeout and wait_timeout at 1814400 (seconds) to no avail.
So ... why is my connection broken after reading for 6:15 (375 seconds)?
(Also, why is this exception swallowed when I use the official binary? It looks like it should bubble up to my application code.)