Am I connecting to the database correctly?
When connecting, an error occurs on adapter.Fill(table);
using MySql.Data.MySqlClient; ... private void buttonOk_Click(object sender, EventArgs e) { timer2.Start(); } public static string Datasource = "localhost"; public static string Port = "3306"; public static string InitialCatalog = "user"; public static string Username = "user"; public static string Password = "pass"; //MySql MySqlConnection connection = new MySqlConnection("datasource=" + Datasource + ";port=" + Port + ";Initial Catalog='" + InitialCatalog + "';username=" + Username + ";password=" + Password); MySqlDataAdapter adapter; DataTable table = new DataTable(); public void MySqlConnect() { adapter = new MySqlDataAdapter("SELECT `username`, `password` FROM `users` WHERE `username` = '" + textBoxUsername.Text + "' AND `password` = '" + textBoxPassword.Text + "'", connection); adapter.Fill(table); //PROBLEM if (table.Rows.Count <= 0) { panel1.Height = 0; labelMessage.ForeColor = Color.Red; labelMessage.Text = "Username Or Password Are Invalid"; timer1.Start(); } else { panel1.Height = 0; labelMessage.ForeColor = Color.Green; labelMessage.Text = "Login Successfully"; timer1.Start(); } table.Clear(); } private void timer1_Tick(object sender, EventArgs e) { if (panel1.Height != 100) { panel1.Height = panel1.Height + 5; if (panel1.Height == 100) { timer1.Stop(); } } } private void timer2_Tick(object sender, EventArgs e) { if (panel1.Height != 0) { panel1.Height = panel1.Height - 5; if (panel1.Height == 0) { timer2.Stop(); } } } private void checkBoxShowPass_CheckedChanged(object sender, EventArgs e) { if (checkBoxShowPass.Checked) { textBoxPassword.UseSystemPasswordChar = true; } else { textBoxPassword.UseSystemPasswordChar = false; } } ... Error text
MySql.Data.MySqlClient.MySqlException HResult=0x80004005 Сообщение = Authentication to host 'localhost' for user 'user' using method 'mysql_native_password' failed with message: Access denied for user 'user'@'localhost' (using password: YES) Источник = MySql.Data Внутреннее исключение 1: MySqlException: Access denied for user 'user'@'localhost' (using password: YES)