试图在MySQL中读取流错误的过去结束

Aus*_*tin 14 .net mysql connector ioexception

我遇到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.
Run Code Online (Sandbox Code Playgroud)

我在夜间运行时会发生此错误.并且它很少发生,所以很难找到为什么会发生这种情况.我使用.NET 3.5与MySQLConnector 6.2.4.0.

我正在使用以下代码运行它.

        public DataSet Read(String query, List<KeyValuePair<String, object>> 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<String, object> 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;
    }
Run Code Online (Sandbox Code Playgroud)

正如你所看到的,我并没有手动尝试读取任何内容> <我正在做的事情adapter.fill(x),所以我无法控制读取流的末尾.

为什么会发生这种情况?

如果您需要更多详细信息,请与我们联系.

Nik*_*696 7

当超过超时时,它看起来像是抛出了它.有一个错误修复它没有这样做,所以如果他们修复它,现在它确实.

connector-net-en.a4.pdf(MySQL文档)

当超过net_write_timeout时,MySQL Connector/NET没有抛出EndOfStreamException异常.(缺陷号53439)

  • 知道解决方案是什么的吗? (3认同)
  • 谢谢!超时是问题。向连接字符串添加更大的值会有所帮助。例如`....database=sample_db;ConnectionTimeout=600;DefaultCommandTimeout=600;` (2认同)