https://support.microsoft.com/en-us/kb/904803

Character data is represented incorrectly when the code page of the client computer differs from the code page of the database in SQL Server 2005

SYMPTOMS

Consider the following scenario:

  • In Microsoft SQL Server 2005, you use SQL Server Management Studio to query character data from a SQL Server database that uses a non-Unicode data type. For example, the SQL Server database uses the char data type, thevarchar data type, or the text data type.
  • The code page of the client computer differs from the code page of the database. The code page is associated with the collation of the database.

In this scenario, character data is represented incorrectly.
For example, you may experience one of the following problems:

  • The character data is represented as a question mark (?). You may see this problem if you inserted or updated the character data as a non-Unicode data type before you queried the character data. This problem occurs if you make this change by using SQL Server Management Studio on a client computer that has a different code page.
  • The character data is represented as corrupted data. The character data of code page X is stored in a non-Unicode column of code page Y. Additionally, the character data is not translated. This problem occurs when you query the character data by using SQL Server Management Studio.
    Note When you query the character data by using SQL Query Analyzer in Microsoft SQL Server 2000, the character data is represented correctly if the Perform translation for character data setting (the Auto Translateparameter) is disabled. The Auto Translate parameter is a parameter of the ConnectionString property for Microsoft OLE DB Provider for SQL Server and for Microsoft .NET Framework Data Provider for OLE DB.
CAUSE

This problem occurs because the character data of code page X is stored in a non-Unicode column of code page Y. Additionally, the character data is not translated correctly. We do not support storing the character data of code page Xin a column of code page Y.
In SQL Server 2005, when you use a string literal of a non-Unicode data type, the string literal is converted by using the database's default code page that is derived from the database's collation. Storing the character data of code page X in a column of code page Y may cause data loss or data corruption.
If the character data is represented as corrupted data, the data can be represented correctly only if you disable the Auto Translate parameter for Microsoft OLE DB Provider for SQL Server or for Microsoft .NET Framework Data Provider for OLE DB.
Note SQL Server Management Studio uses Microsoft .NET Framework Data Provider for SQL Server to connect to the SQL Server database. This data provider does not support the Auto Translate parameter.

WORKAROUND

To work around this problem, use one of the following methods.

Method 1: Use a Unicode data type instead of a non-Unicode data type

Change the columns to a Unicode data type to avoid all the problems that are caused by code page translation. For example, use the nchar data type, the nvarchar data type, or the ntext data type.
For more information about storing Unicode data, click the following article number to view the article in the Microsoft Knowledge Base:

239530 You must precede all Unicode strings with a prefix N when you deal with Unicode string constants in SQL Server

Method 2: Use an appropriate collation for the database

If you must use a non-Unicode data type, always make sure that the code page of the database and the code page of any non-Unicode columns can store the non-Unicode data correctly. For example, if you want to store code page 949 (Korean) character data, use a Korean collation for the database. For example, use the Korean_Wansung_CI_AS collation for the database.

Method 3: Use the binary data type or the varbinary data type

If you want the database to directly store and retrieve the exact byte values of the characters that are handled without trying to perform appropriate code page translation, use the binary data type or the varbinary data type.

Method 4: Use a different tool to store and retrieve data, and disable the Auto Translate parameter

Warning We do not test or support storing the character data of code page X in a column of code page Y. This operation may cause linguistically incorrect query results, incorrect string matching or ordering, and unexpected code page translation (data corruption). We encourage you to use one of the other methods to work around this problem.
When you use Microsoft OLE DB Provider for SQL Server to connect to a database that has a different code page and you try to query character data from a non-Unicode data type column, you must make sure that you store the untranslated characters to the database.
Note The following example assumes that the code page of the client computer is Korean (CP949) and that the code page of the SQL Server database is English (CP1252). You must replace the placeholders in the code examples with values that are appropriate for your situation.
To work around this problem, follow these steps:

  • Manually convert the characters to raw data, and then insert the data into the database by using the code page of the database. To do this, use code that is similar to the following code example.

    string strsrc="가";string strsrc="가";
    string strtag=Encoding.GetEncoding(1252).GetString(Encoding.GetEncoding(949).GetBytes (strsrc));
    sql="insert into <tablename> (<column>,) values ('" + strtag + "')";
    // code for updating the database;

    Note This code example is written in C#.

  • When you want to query the data, use Microsoft OLE DB Provider for SQL Server or Microsoft .NET Framework Data Provider for SQL Server to connect to the database, and then set the Auto Translate parameter to False. To do this, use code that is similar to the following code example.
    OleDbConnection conn=new OleDbConnection("Provider=SQLOLEDB;" +
    " Initial Catalog =<yourdatabase>;"+
    "User id=<youruserid>; Password=<yourpassword>;"+
    "Auto Translate=False"
    );
    // code for representing the character data;
STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.

MORE INFORMATION
Steps to reproduce the problem
  • On the client computer that has Korean (CP949) as the default code page, start SQL Server Management Studio.
  • Connect to a database that has English (CP1252) as the default code page.
  • Create a table in the database by using the following line of code.
    Create table tbTest (A char(20), NA nchar(10), Comment char(20))
  • Insert a Korean character to the database by using the following query.
    Insert into tbTest (A,NA,Comment) values('가',N'가','SQL2005/INSERT')
  • Create a select query to retrieve the data by using the following line of code.
    select * from tbTest

You receive the following results. The value in column A is a question mark.

A                    NA         Comment
-------------------- ---------- --------------------
? 가 SQL2005/INSERT
REFERENCES

For more information about the SQL Server collation and the Auto Translate parameter, click the following article numbers to view the articles in the Microsoft Knowledge Base:

162367 How to transfer Korean Double Byte Character Set chars

234748 You cannot correctly translate character data from a client to a server by using the SQL Server ODBC driver if the client code page differs from the server code page

For more information about SQL Server Unicode data types, visit the following Microsoft Developer Network (MSDN) Web site:

http://msdn2.microsoft.com/en-us/library/aa902669(SQL.80).aspx

转载:Character data is represented incorrectly when the code page of the client computer differs from the code page of the database in SQL Server 2005的更多相关文章

  1. 如何对SQL Server 2005进行设置以允许远程连接(转载)

    如何对SQL Server 2005进行设置以允许远程连接(转载) 在尝试从远程计算机连接到 Microsoft SQL Server 2005 实例时,可能会接收到错误消息.在使用任何程序连接到 S ...

  2. 转载--SQL Server 2005的XQuery介绍

    原文地址: http://bbs.51cto.com/thread-458009-1-1.html   引用: 摘要 本文介绍了SQL Server 2005能够支持的XQuery的各方面特性如FLW ...

  3. 在SQL SERVER 2005中还原数据库时出现错误:system.data.sqlclient.sqlerror 媒体集有 2 个媒体簇 但只提供了 1 个。必须提供所有成员。 (microsoft.sqlserver.smo)

    问题:在SQL SERVER 2005中还原数据库时出现错误:system.data.sqlclient.sqlerror 媒体集有 2 个媒体簇 但只提供了 1 个.必须提供所有成员. (micro ...

  4. (转载)SQL Server 2005 如何启用xp_cmdshell组件

    原文地址:http://www.cnblogs.com/atree/p/SQL_SERVER_xp_cmdshell.html [错误描述]: SQL Server阻止了对组件‘xp_cmdshell ...

  5. SQL Server 2005 发布 订阅 (配置实例[图])(转载)

    2.1          发布&订阅 1.       测 试环境: Item 发布机 A 订阅机 B OS Windows 2003 Server Windows 2003 Server S ...

  6. SQL Server 2005 数据库复制(转载)

    对于一个地域分散的大型企业组织来说,构建具有典型的分布式计算机特征的大型企业管理信息系统时,总要解决一个很重要的问题:如何在多个不同数 据库服务器之间保证共享数据的一致性.之所以有这个重要的问题在于企 ...

  7. (转载)SQL Server 2005 日志文件过大处理

    由于安装的时候没有计划好空间,默认装在系统盘,而且又没有做自动备份.截断事务日志等,很快LDF文件就达到十几G,或者几十G ,此时就不得不处理了. 备份和计划就不说了,现在就说下怎么把它先删除吧: 1 ...

  8. win7(windows 7)系统下安装SQL2005(SQL Server 2005)图文教程——转载

    操作系统:Microsoft Windows 7 旗舰版(32位) 数据库版本:SQL Server 2005 简体中文开发板 数据库下载链接:http://pan.baidu.com/share/l ...

  9. 转载 :sql server 2005 无法删除数据库 "#Test",因为该数据库当前正在使用

    无法删除数据库 "#Test",因为该数据库当前正在使用 --查询分析器中执行下面的语句就行了. use master go declare @dbname sysname set ...

随机推荐

  1. php连接oracle10数据库 转载

    本文转载自:http://blog.csdn.net/wzg199088/article/details/6678241 一.配置环境: 访问Oracle8以上的数据库需要用到Oracle8Call- ...

  2. How Tomcat Works(六)

    本文继续分析HttpProcessor类,该类实现了org.apache.catalina.Lifecycle接口和java.lang.Runnable接口 我们先分析它的构造函数 /** * The ...

  3. Tomcat 系统架构与设计模式,第 1 部分: 工作原理(转载)

    简介: 这个分为两个部分的系列文章将研究 Apache Tomcat 的系统架构以及其运用的很多经典设计模式.本文是第 1 部分,将主要从 Tomcat 如何分发请求.如何处理多用户同时请求,还有它的 ...

  4. CENTOS LINUX查询内存大小、频率

    more /proc/meminfo dmidecode [root@barcode-mcs ~]# dmidecode -t memory linux下查看主板内存槽与内存信息 1.查看内存槽数.那 ...

  5. OC:面向对象的编程思想、基本的知识点总结、强,弱引用

    OC 面向对象 和 面向过程 参考 面向过程:使用步骤划分功能,然后用函数一步一步的调用 面向对象:OOP (Object Oriented Programming) 使用功能来简化问题, 面向对象语 ...

  6. [GUI]界面开发类库-Ribbon风格 [转]

    [GUI]界面开发类库 如果我们不十分清楚需要什么样的界面风格及如何实现,请按以下两个步骤操作: (1)       搞清楚这种风格叫什么名字 (2)       查现有的比较著名的GUI库是否已有相 ...

  7. 30.怎样在Swift中添加运行时属性?

    和OC一样,Swift中也可以添加运行时属性.下面将提供一个完整的例子,演示如何给按钮点击事件添加运行时属性. 1.示例 import UIKit var s_GofButtonTouchDownKe ...

  8. Ehcache(05)——缓存的查询

    http://haohaoxuexi.iteye.com/blog/2117505 缓存的查询 目录 1.    使Cache可查询 1.1     基于Xml配置 1.2     基于代码的配置 2 ...

  9. Unity学习笔记(一)——基本概念之场景(Scene)

    场景,顾名思义就是我们在游戏中所看到的物品.建筑.人物.背景.声音.特效等,基本上和我们玩游戏时所看到的游戏“场景”是同一个概念. Unity 3D中,“场景”是一个视图,我们通过“场景”这个视图,来 ...

  10. 71道经典Android面试题和答案

    ,,面试题1.        下列哪些语句关于内存回收的说明是正确的? (b ) A. 程序员必须创建一个线程来释放内存  B.内存回收程序负责释放无用内存   C.内存回收程序允许程序员直接释放内存 ...