Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-26105

MariaDB 10.6 cannot be used from C# client applications

Details

    Description

      This is because the character set 'utf8mb3' is not supported by the .Net Framework.
      Since version 10.6 utf8 defaults to utf8mb3 but the this can be prevented by starting the server with the option 'old_mode='.
      However the system character set is utf8mb3 and this cannot be changed. Then each command answered by the system cause the client to crash.
      For instance, using the MyTest C# client (uploaded):

      Chose MariaDB version:6
      Query: drop table t1;
      Done.
      Query: create table t1 (n int, m varchar(50)) default charset utf8;
      Done.
      Query: insert into t1 values(1, 'Déjà Noël ?');
      Done.
      Query: select * from t1;
      System.Int32: n = 1
      System.String: m = Déjà Noël ?
      ============================
      Query: show create table t1;
      System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
         at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
         at MySql.Data.MySqlClient.MySqlField.SetFieldEncoding()
         at MySql.Data.MySqlClient.NativeDriver.GetColumnData(MySqlField field)
         at MySql.Data.MySqlClient.NativeDriver.GetColumnsData(MySqlField[] columns)
         at MySql.Data.MySqlClient.Driver.GetColumns(Int32 count)
         at MySql.Data.MySqlClient.ResultSet.LoadColumns(Int32 numCols)
         at MySql.Data.MySqlClient.ResultSet..ctor(Driver d, Int32 statementId, Int32 numCols)
         at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
         at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
         at MySql.Data.MySqlClient.MySqlDataReader.Close()
         at MySql.Data.MySqlClient.MySqlCommand.ResetReader()
         at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
         at MySql.Data.MySqlClient.MySqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
         at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
         at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
         at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
         at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
         at MyTest.Program.Main(String[] args) in C:\vc2013\Projects\MyTest\MyTest\Program.cs:line 52
      Press any key to continue . . .
      

      Setting 'old_mode=' made the t1 table work, but any SHOW commands will crash the client, even a simple command such as:

      select version();
      

      doesn't work.

      Note: Setting manually the variable character_set_results to anything other then utf8mb3 (which seems to be its default value) avoids these crashed but this should be also the result of the old_mode setting.

      It should be also possible to set the character_set_results variables in my.ini but on Windows 10 trying to do this fails. The server cannot be started saying "unknown variable character_set_results" or "unknow variable character-set-results" depending on what was used in my.ini.
      See MDEV-26107.

      Attachments

        1. Connect.cs
          2 kB
          Olivier Bertrand

        Issue Links

          Activity

            This is, of course, a deficiency of mysql-connector-net, not knowing utf8mb3 character set.

            But the question is, if there is an workaround for our users? If I understand you correctly, C# client can set the result charset, can it? if this is the case, then I would think it's a reasonable workaround, until MySQL adds utf8mb3 to their connector.

            serg Sergei Golubchik added a comment - This is, of course, a deficiency of mysql-connector-net, not knowing utf8mb3 character set. But the question is, if there is an workaround for our users? If I understand you correctly, C# client can set the result charset, can it? if this is the case, then I would think it's a reasonable workaround, until MySQL adds utf8mb3 to their connector.

            Sure enough, I did it and it works (still requiring old_mode=)

            bertrandop Olivier Bertrand added a comment - Sure enough, I did it and it works (still requiring old_mode=)
            MaxHayman Max Hayman added a comment - - edited

            Hello,

            I am also having this issue. I tried switching completly to utf8mb4 but I cant seem to make this issue disappear when doing something like

            "SELECT * FROM information_schema.TABLES WHERE TABLE_NAME = 'xxxx'"

            I tried setting the character set in the connection string but this seemed to happen consistently.

            I am using docker and have switched back down to 10.5.

            MaxHayman Max Hayman added a comment - - edited Hello, I am also having this issue. I tried switching completly to utf8mb4 but I cant seem to make this issue disappear when doing something like "SELECT * FROM information_schema.TABLES WHERE TABLE_NAME = 'xxxx'" I tried setting the character set in the connection string but this seemed to happen consistently. I am using docker and have switched back down to 10.5.
            bertrandop Olivier Bertrand added a comment - - edited

            The system character set is used only internally by MariaDB and does not need to be changed. In my client program written in C# here is what I did after connecting to make it work with MariaDB 10.6:

            MySqlCommand setcmd = new MySqlCommand("SET character_set_results=utf8", conn);
            int n = setcmd.ExecuteNonQuery();
            setcmd.Dispose();
            

            in this command utf8 was defaulted to utf8mb4 by MariaDB due to the old_mode setting. That is the results charset that was causing problem with my program.

            bertrandop Olivier Bertrand added a comment - - edited The system character set is used only internally by MariaDB and does not need to be changed. In my client program written in C# here is what I did after connecting to make it work with MariaDB 10.6: MySqlCommand setcmd = new MySqlCommand("SET character_set_results=utf8", conn); int n = setcmd.ExecuteNonQuery(); setcmd.Dispose(); in this command utf8 was defaulted to utf8mb4 by MariaDB due to the old_mode setting. That is the results charset that was causing problem with my program.

            Reported to MySQL as Bug #105516

            serg Sergei Golubchik added a comment - Reported to MySQL as Bug #105516
            alex2 Alex added a comment -

            Has been fixed with MySQL Connector/NET 8.0.28 which has been released 2022-01-18: https://dev.mysql.com/doc/relnotes/connector-net/en/news-8-0-28.html

            alex2 Alex added a comment - Has been fixed with MySQL Connector/NET 8.0.28 which has been released 2022-01-18: https://dev.mysql.com/doc/relnotes/connector-net/en/news-8-0-28.html

            People

              bar Alexander Barkov
              bertrandop Olivier Bertrand
              Votes:
              6 Vote for this issue
              Watchers:
              20 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.