'System.NotSupportedException: Character set 'utf8mb3' is not supported by .Net Framework
I am trying to run a server with a MySQL Database, however I keep getting this huge error and I am not sure why.
[21:15:49,107] Server Properties Lookup: Error While Initialization
DOL.Database.DatabaseException: Table DOL.Database.ServerProperty is not registered for Database Connection...
at DOL.Database.ObjectDatabase.SelectAllObjects[TObject]()
at DOL.GS.ServerProperties.Properties.get_AllDomainProperties()
at DOL.GS.ServerProperties.Properties.InitProperties()
at DOL.GS.GameServer.InitComponent(Action componentInitMethod, String text)```
also this error
[21:15:35,991] ExecuteSelectImpl: UnHandled Exception for Select Query "DESCRIBE `Specialization`"
System.NotSupportedException: Character set 'utf8mb3' is not supported by .Net Framework.
at MySql.Data.MySqlClient.CharSetMap.GetCharacterSet(DBVersion version, String charSetName)
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.ExecuteReader()
at DOL.Database.SQLObjectDatabase.ExecuteSelectImpl(String SQLCommand, IEnumerable`1 parameters, Action`1 Reader)```
Solution 1:[1]
In my case I had installed 10.6.4-MariaDB
that came by default with utf8mb3
.
I got the same error when trying to read tables.
I had fixed it by changing all charset settings in MariaDB configuration to utf8mb4
.
Then dumping my database and importing it again. This time specifying utf8mb4
when creating the database.
So the normal SELECT
,UPDATE
queries were working fine, no more error.
But I kept getting an error when my application was calling stored procedures.
I think maybe that was because the stored procedures are saved into the information_schema
database, that was still utf8mb3
and I could not find a way to change it to utf8mb4
.
After losing a lot of time trying to implement some weird workarounds, I had run into this bug report:
MariaDB 10.6 cannot be used from C# client applications:
https://jira.mariadb.org/browse/MDEV-26105?attachmentViewMode=list
One of the users there says:
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.
So I ended up adding this in my VB project just before executing my stored procedures:
Dim sqlCommand As New MySqlCommand
sqlCommand.Connection = _MySqlCn
sqlCommand.CommandText = "SET character_set_results=utf8"
sqlCommand.ExecuteNonQuery()
This fixed the error for me.
Also, this is what I had previously changed in MariaDB server configuration:
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
# this is read by the standalone daemon and embedded servers
[server]
# this is only for the mysqld standalone daemon
[mysqld]
old_mode=
character-set-server = utf8mb4
character-set-client=utf8mb4
collation-server = utf8mb4_unicode_520_ci
init-connect='SET NAMES utf8mb4'
Solution 2:[2]
There is an update available to the MySQL Connector/NET.
After updating to version 8.0.28 (NuGet package MySql.Data
) everything is working again.
Solution 3:[3]
Maybe a solution. Source : https://dba.stackexchange.com/questions/8239/how-to-easily-convert-utf8-tables-to-utf8mb4-in-mysql-5-5
Change your CHARACTER SET AND COLLATE to utf8mb4.
For each database:
ALTER DATABASE
database_name
CHARACTER SET = utf8mb4
COLLATE = utf8mb4_unicode_ci;
For each table:
ALTER TABLE
table_name
CONVERT TO CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;
For each column:
ALTER TABLE
table_name
CHANGE column_name column_name
VARCHAR(191)
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;
Worked for me with Powershell and MariaDB 10.6. Hope this will help ;)
Solution 4:[4]
In my case (MariaDB 10.6) helped changing character-set-server
in ...\MariaDB 10.6\data\my.ini from utf8 to utf8mb4. Now everything works fine.
Solution 5:[5]
For .NET CORE 5.0, I had to upgrade 3 NuGet Packages from v.5.0.0 to v.5.0.13:
- MySql.EntityFrameworkCore
- Microsoft.EntityFrameworkCore.Design
- Microsoft.EntityFrameworkCore.Tools
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Alexandru Trandafir Catalin |
Solution 2 | Jeremy Caney |
Solution 3 | Alex Lum |
Solution 4 | AdamA |
Solution 5 | Nata |