How to solve garbled characters in SQL SERVER2005
When using SQL SERVER2005, Chinese characters are often garbled. After research, we found that setting SQL sorting rules can solve this problem.
1. Log on to the Server and open Microsoft SQL Server Management Studio.
2. Right-click the database tutorial to be modified and select "properties ".
3. In the pop-up Database properties window, click "options" on the "select page ".
4. Change the sorting rule from SQL _Latin1_General_CP1_CI_AS to Chinese_PRC_CI_AS.
5. Click OK.
Change varchar to nvarchar
Char to nchar
Note: for example
Two methods:
1:
Do not select Hide advice configuration options during installation
Then select Chinese_PRC in Collation designator and order.
2:
Specifies the language of a field during table creation.
Method COLLATE Chinese_PRC_CS_AS_WS
Example:
Create table test
(
A varchar (255) COLLATE Chinese_PRC_CS_AS_WS NULL,
B varchar (255) COLLATE SQL _latin1_general_cp1_ci_as NULL
)
Insert test values ('Chinese', 'Chinese ')
After insertion, field a is Chinese, and field B is ??
Other references
Garbled characters are always displayed when Chinese characters are stored in the database. DEBUG found that both Chinese and Service are correct Chinese characters on the page. Change the field value in the database to Chinese (the field type is Nvarchar). The result page is displayed correctly, indicating that the page is correctly set. The problem lies in the database layer.
Then I checked the database connection field and found a parameter.
SendStringParametersAsUnicode = false
Change it to sendStringParametersAsUnicode = true to solve the problem.
Query MSDN information
If the sendStringParametersAsUnicode attribute is set to "true", the string parameter is sent to the server in Unicode format.
If the sendStringParametersAsUnicode attribute is set to "false", the string parameter is sent to the server in non-Unicode format (for example, ASCII/MBCS, not Unicode.
The default value of the sendStringParametersAsUnicode attribute is "true ".