. NET + MySQL combined development (3) Garbled text

Source: Internet
Author: User
Tools used

Mysql5.022
Vs2005 team suite
MySQL connector net 5.0.3
EMS SQL manage 2005 for MySQL

Friends who have used MySQL know that there is a garbled problem, and this problem is caused by incorrect encoding;
Suppose you want to create a simplified Chinese website;
1. Set database Encoding
You can select the encoding when installing mysql. If you have already installed MySQL, you can change the configuration in the my. ini file (which is in the installation directory of MySQL) to achieve the goal. open the file and find the following two steps:[Client]

Port = 3306

[MySQL]

Default-character-set = gb2312

# The default character set that will be used when a new schema or table is
# Created and no character set is defined
Default-character-set = gb2312

change the red part to gb2312
after the database is created, the database directory contains a database. the opt file contains the following content: default-character-set = gb2312
default-collation = gb2312_chinese_ci

encoding Database Consistency
2. Client tool encoding
encoding settings are the same as database encoding settings.
, you can use a client tool to directly write data without generating garbled characters.
3. Web. set the encoding in the
connection string in config, and use connectionstrings >
Add name =" mysqlserver " connectionstring =" Data Source = 127.0.0.1; user id = root; Password = 123; database = book; charset = gb2312 " />
connectionstrings >

Read Write Encoding<GlobalizationResponseencoding= "Gb2312"Requestencoding= "Gb2312"/>

OK. Now the configuration is complete. The website is a simplified Chinese website and no garbled code is found;
If you need to create a traditional Chinese website, change the above encoding to "GBK.

FAQs:
Character Set 'gbk' is not supported
If this problem occurs, you may have used the MySQL connector of the base version, because the character encoding provided in MySQL connector 1.07 is limited and the Web cannot be found. the encoding type set in config, no GBK, but it seems that there is big5. For details, see charsetmap in MySQL connector 1.07 source code. CS file, where

Public   Static Characterset getchararcterset (dbversion version, String Charsetname)
{
Characterset CS = (Characterset) mapping [charsetname];
If (CS =   Null )
Throw   New Mysqlexception ( " Character Set' "   + Charsetname +   " 'Is not supported " );
Return CS;
}

 

Private   Static   Void Loadcharsetmap ()
{
Mapping. Add ( " Latin1 " , New Characterset ( " Latin1 " , 1 ));
Mapping. Add ( " Big5 " , New Characterset ( " Big5 " , 2 ));
.
}

the character encoding provided by MySQL connector 5.03 is quite comprehensive, so 5.03 is recommended, but 5.03 is not compatible with the old MySQL database.
timeout expired. the timeout period elapsed prior to completion of the operation or the server is not responding

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.