Mvc3 entityframework inserts MySQL database garbled characters

Source: Internet
Author: User

It must be unified among the three, such as utf8,
1. MySQL: ensure that all columns are in utf8 format.
2. vs2010: When establishing a connection to the data server, select advance and set chracterset to utf8. In this way, when viewing and changing Mysql Data in vs2010, it won't see a lot of garbled characters because of the mismatch.
3. Entity Framework: our page uses EF to connect to MySQL, which also needs to be set here.
A. use a datasource to create a connection and save the connection string on the web. in config, set characterset to utf8, as in the previous connection. you can check in config, for example:

  1. <Add Name="Cheweidbcontext" Connectionstring="Server = localhost; user id = root; Password = 123456; persist Security info = true; character set = utf8; database = map" Providername="Mysql. Data. mysqlclient" /> 

B. When the EF model is created, the database connection will be selected, and the one mentioned in 1 will be selected. This will ensure that the web page is displayed, and the changed Chinese will be correctly updated to MySQL.
4. webpage: Set to utf8, as shown below:

    1. <Meta Content="Text/html; charset = UTF-8" HTTP-equiv="Content-Type" />

 

 

In my own situation, it is okay to insert Chinese Characters in sqlyog, but once it is inserted in the webpage, it will be displayed in the database ?? Garbled.

 

It can be seen that the encoding problem occurs when the entityframework is updated to the database. According to the above information,

In the Web. config file

<Add name = "testentities" connectionstring = "metadata = Res: // */models. article. CSDL | res: // */models. article. SSDL | res: // */models. article. MSL; provider = MySQL. data. mysqlclient; provider connection string = & quot; server = localhost; user id = root; Password = root; persist Security info = true; database = Test & quot; "providername =" system. data. entityclient "/>

Add character set = utf8.

 

The test is successful.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.