执行MySqlDataReader :: Read()时发生超时

时间:2014-11-13 12:54:07

标签: c# mysql

我在MySqlDataReader对象上调用Read()时遇到以下异常。

using (MySqlConnection con = new MySqlConnection(myConnectionString))
{
     con.Open();
     using (MySqlCommand command = con.CreateCommand())
     {
         command.CommandText = String.Format("SELECT ID FROM MyTable WHERE ID IN ({0})", idList.ToString());
         MySqlDataReader reader = command.ExecuteReader();
         while (reader.Read())
         {
             int id = Int32.Parse(reader["ID"].ToString());
             if (!idHashSet.Contains(id))
             {
                 idHashSet.Add(id);
             }                         
         }
    }
}

该程序似乎冻结了大约8个小时,然后最终吐出以下异常和堆栈跟踪。

Timeout can be only be set to 'System.Threading.Timeout.Infinite' or a value > 0.
Parameter name: value
   System.Net.Sockets.NetworkStream.set_ReadTimeout(Int32 value)
   MySql.Data.MySqlClient.TimedStream.StartTimer(IOKind op)
   MySql.Data.MySqlClient.TimedStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   System.IO.BufferedStream.Read(Byte[] array, Int32 offset, Int32 count)
   MySql.Data.MySqlClient.MySqlStream.ReadFully(Stream stream, Byte[] buffer, Int32 offset, Int32 count)
   MySql.Data.MySqlClient.MySqlStream.LoadPacket()
   MySql.Data.MySqlClient.MySqlStream.ReadPacket()
   MySql.Data.MySqlClient.NativeDriver.FetchDataRow(Int32 statementId, Int32 columns)
   MySql.Data.MySqlClient.ResultSet.NextRow(CommandBehavior behavior)
   MySql.Data.MySqlClient.MySqlDataReader.Read()

同一错误发生在同一时间的不同代码段,从不同的服务器读取完全不同的表,所以我倾向于认为客户端存在问题。有什么建议吗?

1 个答案:

答案 0 :(得分:1)

这可能是这个错误:https://bugs.mysql.com/bug.php?id=75604

如果Environment.TickCount翻转(服务器正常运行24.9天后),而您正在执行命令,则连接器将抛出您所看到的确切异常。