Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Mysql UTF8 Encoding

Tags:

I have a mysql database with utf8_general_ci encoding ,

i'm connecting to the same database with php using utf-8 page and file encode and no problem but when connection mysql with C# i have letters like this غزة

i editit the connection string to be like this

server=localhost;password=root;User Id=root;Persist Security Info=True;database=mydatabase;Character Set=utf8 

but the same problem .

like image 939
T4mer Avatar asked Jul 27 '12 13:07

T4mer


2 Answers

Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword; CharSet=utf8; 

Note! Use lower case value utf8 and not upper case UTF8 as this will fail.

See http://www.connectionstrings.com/mysql

like image 64
x06265616e Avatar answered Sep 20 '22 17:09

x06265616e


could you try:

Server=localhost;Port=3306;Database=xxx;Uid=x xx;Pwd=xxxx;charset=utf8;" 

Edit: I got a new idea:

//To encode a string to UTF8 encoding string source = "hello world"; byte [] UTF8encodes = UTF8Encoding.UTF8.GetBytes(source);  //get the string from UTF8 encoding string plainText = UTF8Encoding.UTF8.GetString(UTF8encodes); 

good luck

more info about this technique http://social.msdn.microsoft.com/forums/en-us/csharpgeneral/thread/BF68DDD8-3D95-4478-B84A-6570A2E20AE5

like image 22
Anthony Avatar answered Sep 21 '22 17:09

Anthony