mysql超出流末尾,试图读取过去的MySQL流错误结束

I'm running into a problem with MySQL where I have the following error.

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.

This error occurs when I have this running overnight. And it happens infrequently, so it is hard to track down WHY it's happening. I am using .NET 3.5 with MySQLConnector 6.2.4.0.

I am running it using the following code.

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;

}

As you can see, I am not manually attempting to read anything >< I'm doing an adapter.fill(x), so I have no control over reading past the end of the stream.

Why may be this happening?

Please let me know if you need any more details.

解决方案

It looks like it throws that when the timeout is exceeded. There is a bug fix about it NOT doing so, so if they fixed it, now it does.

MySQL Connector/NET did not throw an EndOfStreamException exception when net_write_timeout was exceeded.

(Bug #53439)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MySQL是一个关系型数据库管理系统,用于存储和管理结构化数据。RDB和AOF是MySQL中的两种备份和持久化数据的方式。 RDB(Redis Database)是Redis的一种持久化方式,它将Redis在某个时间点的全部数据保存到一个紧凑的二进制文件中。相比于AOF(Append Only File),使用RDB来恢复数据速度更快,适合备份、全量复制和灾难恢复等场景。 AOF(Append Only File)是另一种Redis的持久化方式,它以日志的形式记录每个写操作,并将这些写操作追加到文件末尾。AOF文件可以用来恢复数据,保证了更高的数据安全性,因为它可以在每次写操作之后进行同步。然而,由于每个操作都需要写入磁盘,相比于RDB,AOF的写入性能会稍差一些。 在上述引用中提到的数据程中,MySQL数据库通过binlog将数据同步到消息队列(MQ),然后再将数据写入到Redis中,以实现读写分离和提高读写性能。为了避免直接读取MySQL数据库,应该尽量将数据缓存在Redis中,从Redis中获取数据并返回给用户。 然而,如果Redis中的缓存全部无法命中,即缓存雪崩问题,所有的请求都无法在Redis中找到数据,这时就会去MySQL数据库中查找数据,导致MySQL承接高并发的请求,可能会导致MySQL的负载过高而崩溃。 因此,在设计系统架构时,需要合理选择RDB和AOF的持久化方式,并采用合适的缓存策略,以提高系统的性能和可靠性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值