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) 
  • Add the error text to the question - Alexander Muksimov
  • Without information about the error, you can only guess that you did not, it seems that there is no connection.open () - Alexander Muksimov
  • one
    Removed a minus, in the morning, if I have time, I will look, but I promise nothing - Alexander Muksimov
  • one
    That account under which you have the rights to the base? - iluxa1810
  • 2
    Try using the IDE to work with the DBMS to enter the database under this data. - iluxa1810

2 answers 2

Judging by the error, this account has no rights to access this database.

Try using IDE to connect to the database. I am sure that you will get the same error => and your code has nothing to do with and need to dig in the direction of rights.

    I have such a 100% working

     @"user=***;password=***;server=localhost;database=dbname;port=3306;"