Page 1 of 1
Problem with encoding
Posted: Fri 15 Sep 2006 13:57
by e-nvention.com
Hi there,
I have a problem when reading data out of the MySQL Database, I use the following connection string:
Code: Select all
databaseConnection="User Id=***;Password=***;Host=***;Database=***;Unicode=True;
Now in some of my datarows I have some data with special encoding. I.e. "Zürich" and when it is read out of the database it should read "Zürich".
Am I missing a setting? In another application that is written in Java I have no problem with reading out the data correctly.
Any help would be appriciated.
Thanks a lot.
Cedric
Posted: Mon 18 Sep 2006 07:43
by Alexey
Send us small test project if possible to reproduce the problem; it is
desirable to use 'test' schema objects, otherwise include definition of
your own database objects. Do not use third party components. Include your client and server machines' regional settings.
Posted: Mon 18 Sep 2006 10:28
by e-nvention.com
Email sent to your support address.
Thanks.
Cedric
Posted: Mon 18 Sep 2006 10:43
by Alexey
OK. Look forward to the reply.
Posted: Thu 28 Sep 2006 10:10
by Alexey
You 've been answered by e-mail.
Posted: Tue 17 Oct 2006 09:03
by Serious
We think you have invalid data stored in your database.
We reproduced the problem when using mysql command line client to create and fill table. In this case data is stored in cp850 charset. When filling table with MySQLDirect .NET data is stored in latin1 (codepage 1252) charset and no error occurs.
Behaviour does not change if you alter storage option for table column (e.g. CHARACTER SET utf8 COLLATE utf8_general_ci). This means that problem is in data format.
To check that data inserted with MySQLDirect .NET is valid and recognized by server perform 'select upper(city) from afpe_organization' query. Data stored with MySQLDirect .NET will be returned in uppercase, data stored with mysql command line client will not. This means that server cannot identify characters in invalid codepage and does not perform uppercase transformation on some symbols.
We recommend you to fix the database. If this is impossible you can receive any charset data in the following way:
when using Unicode=false
Code: Select all
byte[] data = new byte[256];
int count = (int)reader.GetBytes(columnOffset, 0, data, 0, data.Length);
Console.WriteLine(Encoding.GetEncoding(850).GetString(data, 0, count));
when using Unicode=true
Code: Select all
byte[] data = new byte[256];
int count = (int)reader.GetBytes(columnOffset, 0, data, 0, data.Length);
string defaultString = Encoding.UTF8.GetString(data, 0, count);
byte[] cp850data = Encoding.Default.GetBytes(defaultString);
Console.WriteLine(Encoding.GetEncoding(850).GetString(cp850data));