Issue
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();
}
Solution
I solved the issue by replacing Xamarin.MySql.Data with MySqlConnector. It seems Xamarin.Mysql.Data is outdated or something.
Answered By - Alfe
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.