Save Sinhala Unicode Characters in MySQL Database from C#

So recently I came across this situation where I had to save some Sinhala Unicode text from a ASP.net Web Service to a MySQL Database. But when I executed the program after coding the usual INSERT statements, the text had been saved as a set of question marks (??????) in the database column, which had data type set as VARCHAR. I knew that this is due to the fact that MySQL was unable to recognize the Unicode Stream passed by the C# web service. And finally I came up with a Solution. So here is what you have to do if you ever come across such a situation,

  • Set the database Column data type to VARCHAR or TEXT -type
  • Set the COLLATION type of the column to – utf8_unicode_ci
  • Add the following statement at the end of the Database Connection String, “Charset=utf8”, which is to enable MySQL to recognize the data stream.
  • And we are done !

TADAAAAAAAAAAAAA ! 😀

Now you must be able to save any kind of Sinhala Unicode in your MySQL database from C# application…

 

One thought on “Save Sinhala Unicode Characters in MySQL Database from C#

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s