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 !
Now you must be able to save any kind of Sinhala Unicode in your MySQL database from C# application…