I want to connect to a MySQL database in my Xamarin.Android app, however, no matter which framework (Pomelo, Xamarin.MySql.Data, etc.), it writes "Unable to connect to any of the specified MySQL hosts". I have tried everything I could think of. I also have a RAGE:Multiplayer server where everything works fine with the same data, so it should not (?) be due to any firewall settings.
Code:
public static void TryLogin(string username, string password)
{
Connection con = new Connection();
bool tried = con.TryConnection(mContext);
Toast.MakeText(mContext, $"Worked?: {tried}", ToastLength.Long).Show();
}
public class Connection
{
public bool TryConnection(Context context)
{
MySqlConnectionStringBuilder Builder = new MySqlConnectionStringBuilder();
Builder.Port = 3306;
Builder.Server = "localhost";
Builder.Database = "scgp";
Builder.UserID = "root";
Builder.Password = "M9Pb3Tnr3y4DDR4P2I3v";
Console.WriteLine("[Builded Connection String]: " + Builder.ToString());
try
{
MySqlConnection ms = new MySqlConnection(Builder.ToString());
ms.Open();
return true;
}
catch (Exception ex)
{
Toast.MakeText(context, ex.ToString(), ToastLength.Long).Show();
Console.WriteLine(ex.ToString());
return false;
}
}
}
Error:
MySql.Data.MySqlClient.MySqlException: Unable to connect to any of the specified MySQL hosts. at MySql.Data.MySqlClient.NativeDriver.Open () [0x0003f] in <5e4982151d314701bcfe1f0a397fe0db>:0 at MySql.Data.MySqlClient.Driver.Open () [0x0000b] in <5e4982151d314701bcfe1f0a397fe0db>:0 at MySql.Data.MySqlClient.Driver.Create (MySql.Data.MySqlClient.MySqlConnectionStringBuilder settings) [0x00036] in <5e4982151d314701bcfe1f0a397fe0db>:0 at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection () [0x00000] in <5e4982151d314701bcfe1f0a397fe0db>:0 at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection () [0x00083] in <5e4982151d314701bcfe1f0a397fe0db>:0 at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver () [0x00042] in <5e4982151d314701bcfe1f0a397fe0db>:0 at MySql.Data.MySqlClient.MySqlPool.GetConnection () [0x0001c] in <5e4982151d314701bcfe1f0a397fe0db>:0 at MySql.Data.MySqlClient.MySqlConnection.Open () [0x000ad] in <5e4982151d314701bcfe1f0a397fe0db>:0