When I try to connect to the database, it displays an error. When I connect to the database from my computer, everything is fine, and when to the hosting database, the error is:

Caused an exception: "MySql.Data.MySqlClient.MySqlException" in MySql.Data.dll

More information: Authentication to host 'localhost' for user 'id835937_root' using method 'mysql_native_password' failed with message

Code:

string conStr = "SERVER=localhost;" + "DATABASE=!;" + "UID=!;" + "PASSWORD=!;"; using (MySqlConnection con = new MySqlConnection(conStr)) { try { string sql = "INSERT INTO `articles` (`article_title`, `article_text`) VALUES ('hi', 'hello');"; MySqlCommand cmd = new MySqlCommand(sql, con); con.Open(); cmd.ExecuteNonQuery(); MessageBox.Show("Данные добавлены!"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } 
  • Why is it "SERVER = localhost" if hosting should be? - Bulson
  • On the hosting it is directly written “use localhost as a server” - Afik Aliyev
  • Judging by MessageBox.Show(ex.Message); Your program starts on your computer and connects to the database, a cat. on hosting? If yes, then you need to specify the server address, and not lokalkhost. - Bulson
  • @Bulson using 000webhost. It says: the host is localhost, no address of the machine. Can you tell? - Afik Aliyev
  • The situation is not completely clear. Explain where the program is started and where the database is installed. Specify. - Bulson

0