mysql流已关闭,.net – 尝试读取MySQL中流错误的过去结束

我遇到 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中流错误的过去结束 - 乐贴网

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值