温馨提示:本文翻译自stackoverflow.com,查看原文请点击:c# - Is there an easy fix to my code to get the mysql Update statement working in csharp?

c# - 我的代码是否有简单的解决方法,以使mysql Update语句在csharp中工作?

发布于 2020-03-30 21:37:07

晚上好。

我无法使Mysql Update Statement运行。也许我缺少了一些东西。

相同的mysqlconnection可以完美地选择和插入数据。仅供参考,这些部分(选择和插入)被注释掉。

我收到以下4条错误消息:

  • MySqlException:尝试读取结果集时遇到致命错误。
  • MySqlException:从流读取失败。
  • IOException
  • 套接字异常
        MySqlConnection conn = DBUtils.GetDBConnection();
        conn.Open();
        MySqlCommand cmd = conn.CreateCommand();
        string SQL_update = "UPDATE discordbot.tb_lurk SET lupo = lupo + 1 WHERE twitch = '68AFCDC29BFFBDAC4F59A43AE39AFF84'";
        cmd.CommandText = SQL_update;
        cmd.ExecuteNonQuery();
        conn.Close();

工作台中的Tableview:https : //gyazo.com/858f51ea25c4b3526e95c64d5b40afd2

    class DBMySQLUtils
    {

        public static MySqlConnection
                 GetDBConnection(string host, int port, string database, string username, string password)
        {
            // Connection String.
            String connString = "Server=" + host + ";Database=" + database
                + ";port=" + port + ";User Id=" + username + ";password=" + password;

            MySqlConnection conn = new MySqlConnection(connString);

            return conn;
        }

    }    
    class DBUtils
    {
        public static MySqlConnection GetDBConnection()
        {
            string host = "ip-here";
            int port = 3306;
            string database = "discordbot";
            string username = "discordbot";
            string password = "pwhere";

            return DBMySQLUtils.GetDBConnection(host, port, database, username, password);
        }

    }

完全例外:

MySql.Data.MySqlClient.MySqlException
  HResult=0x80004005
  Message=Fatal error encountered during command execution.
  Source=MySql.Data
  StackTrace:
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()
   at sqltest.Program.Main(String[] args) in C:\Users\chaos\Dropbox\Visual Studio\Mysqltest\sqltest\sqltest\Program.cs:line 35

Inner Exception 1:
MySqlException: Fatal error encountered attempting to read the resultset.

Inner Exception 2:
MySqlException: Reading from the stream has failed.

Inner Exception 3:
IOException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

Inner Exception 4:
SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

在此先感谢

查看更多

提问者
Salt
被浏览
10
Salt 2020-02-01 03:30

好的,伙计们,我感谢所有尝试帮助我的人。

我发现了错误。Mysql Server在5.7.17版本上运行。我没有更新服务器,而是在Windowsserver 2012上安装了新版本的Mysql Benchmark。我无法打开新的Benchmark,但它解决了通信问题。

我不知道某些语句为什么起作用(插入,选择),但是UPDATE却不起作用。

发布
问题

分享
好友

手机
浏览

扫码手机浏览