Search code examples
c#mysqlmariadb

Failed to connect to MariaDB after upgrade to version 10.11.5 from c#


After upgrade on MariaDB to version 10.11.5 my connection code not working.

I use MySql.Data.MySqlClient but every time I receive a error:

System.InvalidCastException: Object cannot be cast from DBNull to other types.

My code is very simple on console application on c# just for testing.

using MySql.Data.MySqlClient;

string cs = @"server=192.168.0.1;userid=uName;password=passwd;database=dbName";

using var con = new MySqlConnection(cs);
try
{
    con.Open();
    Console.WriteLine($"MySQL version : {con.ServerVersion}");
}
catch (Exception ex)
{
    Console.WriteLine(ex.ToString());
}

What is the database connection alternative ?

MySql.Data is version: 8.1.0

All my API's applications stopped working ;(


Solution

  • pre-alpha version of package trying to fix this issue. You can try it and let me know if it helped.

    NuGet: https://www.nuget.org/packages/Jf.MySql.Data.Collations/

    Sources: https://github.com/jeffraska/Jf.MySql.Data.Collations/

    The package is in "works on my computer" state. This means .NET framework 4.5, really old MySql.Data 6.9.7 library and latest MariaDB 10.11.4 currently available in Debian repository. So don't expect miracles.

    It uses standard Command Interceptor functionality of MySql.Data library (https://dev.mysql.com/doc/connector-net/en/connector-net-interceptors.html) to alter all SHOW COLLATION queries and replacing it with SHOW COLLATION WHERE id IS NOT NULL.

    Also the package have functionality to alter MySql.Data's internal charset mapping to allow reading utf8mb3 fields in pre 8.0.28 versions of MySql.Data .