我遇到 MySQL的问题,我有以下错误.
MySqlClient.MySqlException: Fatal error encountered during command execution. --->
MySql.Data.MySqlClient.MySqlException: Fatal error encountered attempting to read the resultset. --->
MySql.Data.MySqlClient.MySqlException: Reading from the stream has failed. --->
System.IO.EndOfStreamException: Attempted to read past the end of the stream.
我在夜间运行时会发生此错误.并且它很少发生,所以很难找到为什么会发生这种情况.我使用.NET 3.5与MySQLConnector 6.2.4.0.
我正在使用以下代码运行它.
public DataSet Read(String query, List> parameters)
{
MySqlDataAdapter adapter = null;
DataSet returnVal = null;
if (query != null && query.Length > 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 < 150)
{
log.Debug(stopwatch.ElapsedMilliseconds + "ms to run query");
}
else
{
StringBuilder sb = new StringBuilder("");
if (parameters != null)
{
foreach (KeyValuePair 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;
}
正如您所看到的,我并非手动尝试阅读任何内容>
最佳答案
当超过超时时,它看起来像是抛出了它.有一个错误修复它没有这样做,所以如果他们修复它,现在它确实.
connector-net-en.a4.pdf (MySQL Documentation)
当超过net_write_timeout时,MySQL Connector / NET没有抛出EndOfStreamException异常.
(缺陷号53439)
点击查看更多相关文章
转载注明原文:.net – 尝试读取MySQL中流错误的过去结束 - 乐贴网