简体   繁体   中英

MySQL: Fatal Error encountered attempting to read the resultset

Whenever my code runs, it works but then also crashes. I'm not sure if it is a time thing, or if another thing happens before that. The error code I get is this在此处输入图像描述

At first, I thought it was just my connect was being closed, but it was not. I'm not sure if it is my command text or what now and all the questions like this haven't been of help.

The code that I have is this

private void On_ProcessExit(object sender, System.EventArgs e)
        {
            Console.WriteLine("Server has crashed...");
            _Proc.Exited -= new EventHandler(On_ProcessExit);

            DB.UpdateActivePID(ServerName, 0);

            if (_UserStop == true && _Proc.HasExited) {return; } //No need to restart server
            else if (_UserStop == false && _Proc.HasExited) //Need to restart the server
            {
                Start();
            }
        }


public static MySqlConnection Connection
        {
            get
            {
                if(connection == null)
                    Open();
                IsConnected();
                return connection;
            }
        }

public static MySqlCommand PrepareCommand(string query, object[] bindings)
        {
            for (int i = 0; i < bindings.Length; i++)
            {
                var regex = new Regex(Regex.Escape("?"));
                query = regex.Replace(query, "@param" + i, 1);
            }

            var cmd = Connection.CreateCommand();
            cmd.CommandText = query;
            cmd.Prepare();
            int index = 0;
            foreach (object o in bindings)
            {
                cmd.Parameters.AddWithValue("@param" + index, o);
                index++;
            }
            return cmd;
        }

  public static void ExecuteUpdate(string query, params object[] bindings)
        {
            if (Connection == null) return;

            MySqlCommand cmd = PrepareCommand(query, bindings);
            Console.WriteLine("SQL Line: " + cmd.CommandText);
            cmd.ExecuteNonQuery();
        }
public static void UpdateActivePID(string serverName, int pid)
        {
            if (Connection == null) return;
            string query = "UPDATE ServerParameters SET ActivePID = ? WHERE ServerName = ?";
            ExecuteUpdate(query, new object[] { pid,serverName } );
        }

looks like a wrong utf datatype like using utf8mb3_general_ci instead of utf8mb4_general_ci

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM