Bug #61687 Wrong character set for error messages.
Submitted: 29 Jun 2011 9:20 Modified: 25 Aug 2011 13:05
Reporter: Сергей Петров Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:6.4.3 OS:Windows (Seven SP1)
Assigned to: Julio Casal CPU Architecture:Any

[29 Jun 2011 9:20] Сергей Петров
Description:
I am using localized error messages on MySQL server. And when I am using not UTF8 for connection, I am get wrong encoded error message. Look like what server still send error message in UTF8, but connector parse it in specified encoding.

How to repeat:
using System;
using MySql.Data.MySqlClient;

internal static class Test{
    private static void Main(string[] args){
        MySqlConnectionStringBuilder mycsb=new MySqlConnectionStringBuilder{
            UserID="UserName",
            Password="Password",
            Database="Test"
        };
        try{
            MySqlHelper.ExecuteNonQuery(mycsb.ToString(),"query with error");
        }catch(MySqlException e){
            Console.WriteLine(e.Message);
        }
        mycsb.CharacterSet="cp1251";
        try{
            MySqlHelper.ExecuteNonQuery(mycsb.ToString(),"query with error");
        }catch(MySqlException e){
            Console.WriteLine(e.Message);
        }
        Console.ReadKey();
    }
}

У вас ошибка в запросе. Изучите документацию по используемой версии MySQL на предмет корректного синтаксиса около 'query with error' на строке 1
У вас ошибка в запросе. Изучите документацию по используемой версии MySQL на предмет корректного синтаксиса около 'query with error' на строке 1
[1 Jul 2011 8:59] Bogdan Degtyariov
Hi Sergey,

Thank you for reporting the bug. I was able to repeat the problem.
My test application displayed the error in KOI8-R encoding. This encoding is used for all Russian error messages in mysql\share\russian\errmsg.sys

Setting the status "Verified" and trying to get more relevant details.
[1 Jul 2011 10:05] Bogdan Degtyariov
The workaround is to set the Charset to KOI8R:

 mycsb.CharacterSet = "koi8r";

Though, it seems to be the server issue because if result is UTF-8 the errors have to be UTF-8 instead of KOI8R.
[1 Jul 2011 10:23] Bogdan Degtyariov
The final proof that the issue is in the server is to try running 

MySqlHelper.ExecuteNonQuery(mycsb.ToString(), "русский текст вызовет ошибку");

which results in the following error message (my Russian text is clearly readable, but the error message is still in KOI8-R):

х ЧБУ ПЫЙВЛБ Ч ЪБРТПУЕ. йЪХЮЙФЕ ДПЛХНЕОФБГЙА РП ЙУРПМШЪХЕНПК ЧЕТУЙЙ MySQL ОБ РТЕДНЕФ ЛПТТЕЛФОПЗП УЙОФБЛУЙУБ ПЛПМП 'русский текст вызовет ошибку' ОБ УФТПЛЕ 1
[1 Jul 2011 10:52] Bogdan Degtyariov
MySQL Servers 5.0.x and 5.1.x fail, but 5.5.9 and newer display everything correctly.

Have you tried recent 5.5 versions?
[1 Jul 2011 10:56] Сергей Петров
>Have you tried recent 5.5 versions?
I am using 5.5.13 and have this issue.
[4 Aug 2011 6:58] Bogdan Degtyariov
Sergey,

Sorry for the late feedback.
What kind of error message do you see when running this line of code?

MySqlHelper.ExecuteNonQuery(mycsb.ToString(), "русский текст вызовет
ошибку");
[4 Aug 2011 7:12] Сергей Петров
using System;
using MySql.Data.MySqlClient;

internal static class Test{

    private static void Main(string[] args){
        MySqlConnectionStringBuilder mycsb=new MySqlConnectionStringBuilder{
            UserID="UserName",
            Password="Password",
            Database="Test"
        };
        try{
            MySqlHelper.ExecuteNonQuery(mycsb.ToString(),"русский текст вызовет ошибку");
        }catch(MySqlException e){
            Console.WriteLine(e.Message);
        }
        mycsb.CharacterSet="cp1251";
        try{
            MySqlHelper.ExecuteNonQuery(mycsb.ToString(),"русский текст вызовет ошибку");
        }catch(MySqlException e){
            Console.WriteLine(e.Message);
        }
    }
}

Results:
У вас ошибка в запросе. Изучите документацию по используемой версии MySQL на предмет корректного синтаксиса около 'русский текст вызовет ошибку' на строке 1
У вас ошибка в запросе. Изучите документацию по используемой версии MySQL на предмет корректного синтаксиса около 'русский текст вызовет ошибку' на строке 1
[12 Aug 2011 8:41] Bogdan Degtyariov
I do not understand why the query and the error message seem to be in the same encoding. The error message could be incorrectly converted, but SQL query (even if syntax is wrong) should be retained.
[12 Aug 2011 13:16] Bogdan Degtyariov
The error message is correct when I run "SET NAMES CP1251;" immediately after connecting. This overrides "SET character_set_results=NULL" executed by driver.
However, character_set_results was set to NULL for purpose, so looking for the real solution....
[25 Aug 2011 13:05] Julio Casal
Thank you for your bug report. This issue has been committed to our source repository of that product and will be incorporated into the next release.

Fixed in 6.3.8 and 6.4.4+.

If necessary, you can access the source repository and build the latest available version, including the bug fix. More information about accessing the source trees is available at

    http://dev.mysql.com/doc/en/installing-source.html