0

I get this error even tho there is no null values passed, also why is it crashing at OpenAsync function.

This is the Error

System.InvalidCastException: Object cannot be cast from DBNull to other types.
   at System.DBNull.System.IConvertible.ToInt32(IFormatProvider provider)
   at MySql.Data.MySqlClient.Driver.LoadCharacterSetsAsync(MySqlConnection connection, Boolean execAsync, CancellationToken cancellationToken)
   at MySql.Data.MySqlClient.Driver.ConfigureAsync(MySqlConnection connection, Boolean execAsync, CancellationToken cancellationToken)
   at MySql.Data.MySqlClient.MySqlConnection.OpenAsync(Boolean execAsync, CancellationToken cancellationToken)
   at ZoneRolePlay.Bot.Authenticator.IsUserVerified(String discordId) in D:\Backupowo\Projects\Old\ZoneRolePlay\ZoneRolePlay.Bot\Authenticator.cs:line 82

This is the Code

public async Task<bool> IsUserVerified(string discordId)
{
    try
    {
        using (MySqlConnection connection = new MySqlConnection(_connectionString))
        {
            await connection.OpenAsync(); // line 82
            string query = $"SELECT * FROM Verified WHERE discord_id = @discordId";
            MySqlCommand command = new MySqlCommand(query, connection);
            command.Parameters.AddWithValue("@discordId", discordId);
            using (DbDataReader reader = await command.ExecuteReaderAsync())
            {
                if (reader.HasRows)
                {
                    return true;
                }
            }
        }
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex);
    }
    
    return false;
}

I made sure that discordId and _connectionString are not nulls, theyre not

Cegla
  • 1
  • 1

0 Answers0