I am working on a Xamarin.Forms Android app, which needs to connect to a MySQL database.
I decided to use MySqlConnector, because it has async methods.
However, when I call OpenAsync() it throws System.IndexOutOfRangeException.
Open() works fine, but I would like to use async. Am I doing something wrong?
Here is my code:
private static MySqlConnection DBConnection;
internal static async Task<bool> SetAndTestConnectionString(string dbendpoint, int userid, string password)
{
DBConnection = new MySqlConnection($" *connection string* ");
bool connectresult= false;
try
{
await DBConnection.OpenAsync();
connectresult= true;
}
catch (Exception e)
{
connectresult= false;
Console.WriteLine(e.Message);
}
return connectresult;
}
SetAndTestConnectionStringin turn?bool connectionsucceeded=await SetAndTestConnectionString();Of course I supply the arguments. If the arguments I pass are incorrect, the exception it throws is somthing like "Cannot connect to host". So I don't think it has much to do with how I call it.OpenAsyncthat throws this exception? Are you using the official MySql connector (that doesn't really support async) or something else?