簡體   English   中英

C#:未處理MySQL異常

[英]C#: MySQL Exception was unhandled

MySql.Data.MySqlClient.MySqlException發生了MySql.Data.dll類型的未處理的異常

附加信息:

Access denied for user 'groupdes_ling'@'60.50.32.226' (using password: YES)

每當我嘗試運行程序時,都會發生此錯誤。 編碼粘貼在下面:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace GroupDesignProject
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

    private void button1_Click(object sender, EventArgs e)
    {

    }

    private void textBox1_TextChanged(object sender, EventArgs e)
    {
        string MyConnectionString = "Server=31.220.105.189;Database=groupdes_GDP;Uid=groupdes_ling;Pwd=0164851286;";

        MySqlConnection connection = new MySqlConnection(MyConnectionString);//create connection
        MySqlCommand cmd;
        connection.Open();//connect to database

            //write INSERT command and execute
            cmd = connection.CreateCommand();//create command
            cmd.CommandText = "INSERT INTO trial (Name)values ('" + textBox1.Text + "');";
            cmd.ExecuteNonQuery();

            //disconnect from database
            if (connection.State == ConnectionState.Open)
            {
                connection.Close();
            }           
    }
}

}

我仍然無法解決這個錯誤。 謝謝您的幫助

您需要將該用戶/主機/密碼組合的權限添加到MySQL實例。 例如;

GRANT ALL ON *.* to 'groupdes_ling'@'60.50.32.226' IDENTIFIED BY 'Password';

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM