Alfe
Alfe

Reputation: 144

'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("Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;");
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();

if(rdr.HasRows)
{
    Toast.MakeText(this, "Successfully Logged In", ToastLength.Short).Show();
}
else
{
    Toast.MakeText(this, "Invalid Username/Password", ToastLength.Short).Show();
 }

Upvotes: 0

Views: 466

Answers (1)

Alfe
Alfe

Reputation: 144

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

Upvotes: 1

Related Questions