Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing tamil language text into MySQL

Am developing a tamil website using ASP.NET MVC and MYSQL.

  1. While updating the values (tamil language text) from ASP.NET MVC website to Database all my values as storing as format like this ??????????????

  2. When I directly run the insert query into my database I am able to insert the tamil text into the database.

Asp.NET MVC : I have the below code

<meta charset="utf-8" />

MySQL - Create table syntax :

CREATE TABLE IF NOT EXISTS `Login` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `username` text COLLATE utf8_unicode_ci,
  `password` mediumtext COLLATE utf8_unicode_ci,
  PRIMARY KEY (`ID`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=6 ;

Note: I have been using the Entity Framework to connect with the MySQL database.

Is any thing missing from my side?

From Comment

Solution Found - just add ";Charset=utf8" to connection string. Here is the working solution:

<add name="photostorageEntities" 
     connectionString="metadata=res://*/Models.Photos.csdl|
                       res://*/Models.Photos.ssdl‌​|res://*/Models.Photos.msl;
       provider=MySql.Data.MySqlClient;
       provider connection string=&quot;server=ServerIP;
       User Id=UID;password=PASS;
       Persist Security Info=True;database=photostorage; Charset=utf8&quot;" 
    providerName="System.Data.EntityClient" />

Thanks everyone! :)

like image 434
Velu Avatar asked Jan 07 '14 15:01

Velu


2 Answers

I also faced the exact same problem.

Add this connection property to the jdbc driver where you are defining the database connection.

<property name="connectionProperties" value="characterEncoding=UTF-8;characterSetResults=UTF-8"/>

I hope this will solve your problem.

like image 170
akkig Avatar answered Sep 30 '22 18:09

akkig


Use following query to set the default character set to already created table

ALTER TABLE Login CONVERT TO CHARACTER SET utf8;

You are using collate in multiple places. The following will be enough

CREATE TABLE IF NOT EXISTS `Login` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `username` text,
  `password` mediumtext,
  PRIMARY KEY (`ID`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=6 ;
like image 43
Pandiyan Cool Avatar answered Sep 30 '22 20:09

Pandiyan Cool