Google
 

Thursday, November 20, 2008

Storing Arabic (or Unicode) data in MySQL using Connector/Net 5.2

Storing Unicode data in varchar columns in MySQL can be tricky. I spent some time to use MySQL Connector/Net 5.2 to store Arabic data.
Once you know it, it's simple:

  • The varchar column Charset should be utf8
  • The varchar column Collate property should be utf8_general_ci. I tried utf8_bin and worked too. This is a screen shot from MySQL Administrator table editor:


  • In the .net application, the connection string must include charset=utf8. For example:

"server=localhost;uid=root;password=123;database=test;port=3306;charset=utf8"

10 comments:

Anonymous said...

thanks it was helpfull for me

Anonymous said...

Thanks 1000 times, i was searching for this solution for the whole day.
that is what i called professional developer.

faheem said...

it works man
thanks (Y)

ansar said...

Hi,
I am trying to save hindi words to mySQL using ASP.Net and also want to display it. I dont know how it is possible. As you said in your post, I have created a database and a field with utf8 as you mentioned. Then I just copy a hindi word and paste it into a textbox in asp.net. Then I save this field into above field in the mySQL. When I go to database it is seen as ||||||. Can you give me a help for saving and display hindi words using asp.net and mySQL.

Ramzi Komati said...

It didn't work with me at all... I could store Arabic characters in the MySQL field but I couldnt read/write Arabic in the MySQL database from my ASP.Net files.

Ramzi Komati said...

I've been trying for severals days finding a solution for this problems. I tried using PHP and it works perfectly... I can read/write Arabic characters in/from MySQL database. However with ASP.Net I can't get it work!

Microsoft SQL is much more easier to read/write Arabic (and Hindi and other)characters in ASP.Net, by assigning the NVARCHAR data type.

So I'd recommend Ansar to store your information on MS SQL instead of MySQL for ASP.Net application.

Rajesh said...

Thanks, for the post , it really worked appending the database connection string with charset=utf8 and changing the mysql db schema to utf8 charset.

Anonymous said...

Thank you, it was helpfull for me

Majdi Aburahelah said...

Many thanks. it's solve my issue.

for IT the said...

This is an amazing blog,it gives very helpful messages to us.Besides that Wisen has established as Best Dot Net Training in Chennai. or learn thru ASP.NET Online Training . Nowadays Dot Net has tons of job opportunities on various vertical industry.