Bug #25385 Problems with accents in .NET DataTable column name
Submitted: 3 Jan 2007 13:01 Modified: 17 Oct 2007 19:43
Reporter: Gilles TOURREAU Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:5.0.2 OS:Microsoft Windows (WinXP)
Assigned to: CPU Architecture:Any
Tags: .NET; 2.0; DataTable; accent; column name;

[3 Jan 2007 13:01] Gilles TOURREAU
Description:
We have some tables with some accents in column name, like "Modèle" for example.

When I fill a DataTable with .NET, we find that column name in DataTable looks like : "Modèle"...

Our configuration:

mySQL : 5.0.27-community-nt

Driver : 5.0.2-beta (For VS-2005)

.NET Framework : 2.0

Visual Studio : 2005 SP1

Operating System : XP Pro SP2 (for mysql and application with driver)

How to repeat:
1/Create a table (MyTable) in MySQL with a column named : "Modèle" varchar(20)

2/Fill it with some values

3/Create a Windows Project for .NET (C#) with a reference to MySQL Driver (Project or compiled library).

4/Create a Form and add this within the Form constructor :

 

this.mySqlConnection1 = new MySql.Data.MySqlClient.MySqlConnection();

this.mySqlDataAdapter1 = new MySql.Data.MySqlClient.MySqlDataAdapter();

this.mySqlCommand1 = new MySql.Data.MySqlClient.MySqlCommand();

 

this.mySqlDataAdapter1.SelectCommand = this.mySqlCommand1;

 

this.mySqlCommand1.CommandText = "SELECT * FROM MyTable";

this.mySqlCommand1.Connection = this.mySqlConnection1;

 

this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

this.AutoScaleMode System.Windows.Forms.AutoScaleMode.Font;

this.ClientSize = new System.Drawing.Size(292, 266);

this.Name = "Form1";

this.Text = "Form1";

 

Add this in private members :

 

private MySql.Data.MySqlClient.MySqlConnection mySqlConnection1;

private MySql.Data.MySqlClient.MySqlDataAdapter mySqlDataAdapter1;

private MySql.Data.MySqlClient.MySqlCommand mySqlCommand1;

 

5/Add a button and add an event for « Click ».

6/Put this code in the method of click button :

 

MySqlConnectionStringBuilder sb;

 

sb = new MySqlConnectionStringBuilder();

sb.Server = "myHost";

sb.Database = "myDataBase";

sb.UserID = "myLogin";

sb.Password = "myPass";

 

this.mySqlConnection1.ConnectionString sb.ConnectionString;

 

DataTable dt;

dt = new DataTable();

 

this.mySqlConnection1.Open();

 

this.mySqlDataAdapter1.Fill(dt);

 

this.mySqlConnection1.Close();

 

7/Put a breakpoint behind the line : "this.mySqlDataAdapter1.Fill(dt);"

8/Execute it with Visual Studio debugger...

9/Execute one step (in order to execute the method (Fill))

10/Watch the content of expression "dt.Columns[0].ColumnName" and you can see the problem with accent (column name is : Modèle)

Suggested fix:
After test, it should be an encoding problem...

I think it's in the following method :

   MySql.Data.MySqlClient.NativeDriver.GetFieldMetaData41()

 around this line : "field.ColumnName stream.ReadLenString();"
[8 Jan 2007 21:55] Reggie Burnett
Gilles

Are you using an appropriate character set?  You should remember that unless you set a character set, the symbols that come back will be in the default character set which may be latin1.  Add something like "char set = utf8" to your connection string and try again.

Thanks
[9 Jan 2007 14:09] Gilles TOURREAU
I try it in my connection string :

Server=myHost;Database=myDataBase;User Id=MyUser;Password=MyPass;Character Set=utf8

and

Server=myHost;Database=myDataBase;User Id=MyUser;Password=MyPass;Character Set=latin1

And i have the same problem...
[15 Jan 2007 10:26] Tonci Grgin
Hi Gilles. This is actually duplicate of Bug#23657 which is closed but I see the same behavior with today c/NET 5 sources. I am referring to my test case provided in Bug#23657:
 - Inspecting "objDT.Columns(0).ColumnName" gives wrong value for column name (wrong accents)
 - Displaying column name in label with EE font (cp 1250) gives correct result (correct accents displayed)
 - Displaying column name in label with generic font set to EE script (cp 1250) gives wrong result (displays wrong accents)
[26 Jan 2007 18:35] Reggie Burnett
I am still unable to reproduce this.  I'm using the following as a test case and it passes.

[Test]
public void Test1()
{
    using (MySqlConnection c = new MySqlConnection(GetConnectionString(true) + ";charset=utf8"))
    {
        c.Open();

        MySqlCommand cmd = new MySqlCommand("CREATE TABLE test (Modèle int)", c);
        cmd.ExecuteNonQuery();

        cmd.CommandText = "INSERT INTO test VALUES (1)";
        cmd.ExecuteNonQuery();

        MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM test", c);
        DataTable dt = new DataTable();
        da.Fill(dt);

        Assert.AreEqual(1, dt.Columns.Count);
        Assert.AreEqual(1, dt.Rows.Count);
        Assert.AreEqual("Modèle", dt.Columns[0].ColumnName);
     }
 }
[30 Jan 2007 14:48] Tonci Grgin
Gilles, what does Reggies test case say on your machine?
[30 Jan 2007 17:14] Gilles TOURREAU
I have an assertion fail at :

Assert.AreEqual("Modèle", dt.Columns[0].ColumnName);

If I replace this line with :

System.Diagnostics.Debug.WriteLine(dt.Columns[0].ColumnName);

The output result is :
Modèle
[31 Jan 2007 17:54] Reggie Burnett
I can't do anything with this currently. I still do not have any repeatable test case that shows this problem.  I believe there is a problem *somewhere* because you and Tonci both see it but until it fails on my machine I can't fix it.
[11 Jun 2007 8:36] Tonci Grgin
Bug#28328 has been marked as duplicate of this one.
[11 Jun 2007 8:55] Tonci Grgin
This could very well be due to server settings. I have managed to get correct results by putting:
      cmd.CommandText = "SET character_set_results=latin1";
      cmd.ExecuteNonQuery();
in code as I noticed
      3 Query       SET NAMES utf8;SET character_set_results=NULL
in general query log.

Environment:
 - MySQL server 5.0.44BK on WinXP Pro SP localhost
 - NET FW 2.0 with c/NET 5.1.2 and 5.0.7

I think this should be closed as !Bg, Reggie?
[17 Oct 2007 19:43] Reggie Burnett
This is a duplicate of 31185 which has been fixed in 5.1.4 and 5.0.9