[MDEV-26105] MariaDB 10.6 cannot be used from C# client applications Created: 2021-07-07  Updated: 2023-03-24  Resolved: 2023-02-16

Status: Closed
Project: MariaDB Server
Component/s: Character Sets
Affects Version/s: 10.6
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Olivier Bertrand Assignee: Alexander Barkov
Resolution: Fixed Votes: 6
Labels: regression-10.6
Environment:

Windows & Debian


Attachments: Text File Connect.cs    
Issue Links:
Blocks
is blocked by MDEV-27177 OLD_MODE Ignored during initial hand ... Confirmed
Duplicate
duplicates MDEV-26163 after 10.6 upgrade problems connectin... Closed
Problem/Incident
is caused by MDEV-8334 Rename utf8 to utf8mb3 Closed
Relates
relates to MDBF-205 Ecosystem CI - mysql-connector/NET Open
relates to MDEV-26605 Creating table with primary key const... Open
relates to MDEV-26607 Information schema not accessable in ... Open
relates to MDEV-26107 Cannot set character_set variables in... Open
relates to MDEV-26462 MariaDB 10.6.x set caratteri Closed

 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.



 Comments   
Comment by Sergei Golubchik [ 2021-07-08 ]

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.

Comment by Olivier Bertrand [ 2021-07-08 ]

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

Comment by Max Hayman [ 2021-07-28 ]

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.

Comment by Olivier Bertrand [ 2021-07-29 ]

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.

Comment by Sergei Golubchik [ 2021-11-22 ]

Reported to MySQL as Bug #105516

Comment by Alex [ 2022-11-29 ]

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

Generated at Thu Feb 08 09:42:47 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.