简体   繁体   中英

C#: MySQL Exception was unhandled

An unhandled exception of type MySql.Data.MySqlClient.MySqlException occurred in MySql.Data.dll

Additional information:

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

This error occurs whenever i'm trying to run my program. The coding is pasted below:

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();
            }           
    }
}

}

I still can't manage to solve this error. Thanks for the help

You need to add permissions for that user/host/password combination to the MySQL instance. For example;

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

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