MySqlConnector MySqlConnection.OpenAsync() not working

Viewed 250

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;
}
0 Answers
Related