‘Unable to connect to any of the specified mysql hosts.’ error


I have a Xamarin app where you connect to a database. There are no errors in the error list but when I run the code, I get this error: Unable to connect to any of the specified MySQL hosts. I use Xamarin.MySql.Data.

I use the same connection string in a windows forms app and it works totally fine. I wrote it yesterday, it is not an old build.

Here is my code:

MySqlConnection conn  new MySqlConnection("ServermyServerAddress;DatabasemyDataBase;UidmyUsername;PwdmyPassword;");
await conn.OpenAsync();

MySqlCommand cmd  new MySqlCommand("SELECT * FROM users WHERE USERNAME  '" + username.Text + "' AND PASSWORD  '" + password.Text + "'", conn);

cmd.Connection  conn;
MySqlDataReader rdr  cmd.ExecuteReader();

    Toast.MakeText(this, "Successfully Logged In", ToastLength.Short).Show();
    Toast.MakeText(this, "Invalid Username/Password", ToastLength.Short).Show();


I solved the issue by replacing Xamarin.MySql.Data with MySqlConnector. It seems Xamarin.Mysql.Data is outdated or something.

Answered By – Alfe

Leave a Comment