轉載: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

来源:http://www.cnblogs.com/which/archive/2016/02/26/5219637.html
-Advertisement-
Play Games

https://support.microsoft.com/en-us/kb/904803 Character data is represented incorrectly when the code page of the client computer differs from the cod


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


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • pulltorefresh插件可以輕鬆實現上拉下拉刷新,github.com上直接搜索進行下載。 佈局文件: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ptr="http://sc
  • 這篇文章解釋了Java 虛擬機(JVM)的內部架構。下圖顯示了遵守 Java SE 7 規範的典型的 JVM 核心內部組件。 上圖顯示的組件分兩個章節解釋。第一章討論針對每個線程創建的組件,第二章節討論了線程無關組件。 線程 JVM 系統線程 每個線程相關的 程式計數器 棧 本地棧 棧限制 棧幀 局
  • 首先下載xUtils,下載地址:https://github.com/wyouflf/xUtils 把下載好的文件壓縮,把裡面的jar包拷進項目中如圖所示: 這裡新建一個User類進行測試增刪改查 package com.example.xutilsdemo; public class User {
  • 最近公司項目升級重構(重寫),除了本來我所負責的模塊,最後臨危受命接了推送(遠程和本地)相關的模塊,順便把推送的相關知識複習了一遍。後期連續工作十幾天加上最後一天的通(瞎)宵(熬)達(一)旦(夜),也算是不辱使命。此文除了講解遠程推送相關的基本知識外,也會涉及一些推送相關的奇淫技巧。另外本文主要講解
  • RecyclerView是 Android 相容包V21中新推出的列表類,它的自定義化強的優點足以讓它能夠取代GridView和ListView,本文將結合SwipeRefreshLayout與RecyclerView講解如何實現下拉刷新和自動載入的代碼 需要的依賴 以下版本自行更新 Java 1
  • 作為一名iOS開發者,我經歷過幾個沒有設計師的項目,結果就是,痛苦的一逼。做這種類型的項目,設計是非常重要的,特別是迭代設計。 在每個項目最開始的時候,客戶其實並不知道自己想要什麼。直接堆碼之前我們還是有點小小的設計知識更有助於你跟客戶撕逼的時候占上風,其實我們只是想更完美,難道不是嗎? 這裡我更推
  • 什麼是SQLite SQLite是一款輕型的嵌入式資料庫 它占用資源非常的低,在嵌入式設備中,可能只需要幾百K的記憶體就夠了 它的處理速度比Mysql、PostgreSQL這兩款著名的資料庫都還快 什麼是資料庫 資料庫(Database)是按照數據結構來組織、存儲和管理數據的倉庫 資料庫可以分為2大種
  • 當我看到這周的每周一文的題目是“關於對資料庫的認識和理解”的時候,我突然覺得無從下手,因為我不知道寫什麼,自己對資料庫的理解和接觸過的資料庫,僅僅限於課堂上老師講過的微軟公司的SQLServer2008,對於其他的資料庫自己也只是道聽途說。於是乎我瘋狂的在網上找資料,從不同的方面瞭解了當前的幾種主流
一周排行
    -Advertisement-
    Play Games
  • 前言 本文介紹一款使用 C# 與 WPF 開發的音頻播放器,其界面簡潔大方,操作體驗流暢。該播放器支持多種音頻格式(如 MP4、WMA、OGG、FLAC 等),並具備標記、實時歌詞顯示等功能。 另外,還支持換膚及多語言(中英文)切換。核心音頻處理採用 FFmpeg 組件,獲得了廣泛認可,目前 Git ...
  • OAuth2.0授權驗證-gitee授權碼模式 本文主要介紹如何筆者自己是如何使用gitee提供的OAuth2.0協議完成授權驗證並登錄到自己的系統,完整模式如圖 1、創建應用 打開gitee個人中心->第三方應用->創建應用 創建應用後在我的應用界面,查看已創建應用的Client ID和Clien ...
  • 解決了這個問題:《winForm下,fastReport.net 從.net framework 升級到.net5遇到的錯誤“Operation is not supported on this platform.”》 本文內容轉載自:https://www.fcnsoft.com/Home/Sho ...
  • 國內文章 WPF 從裸 Win 32 的 WM_Pointer 消息獲取觸摸點繪製筆跡 https://www.cnblogs.com/lindexi/p/18390983 本文將告訴大家如何在 WPF 裡面,接收裸 Win 32 的 WM_Pointer 消息,從消息裡面獲取觸摸點信息,使用觸摸點 ...
  • 前言 給大家推薦一個專為新零售快消行業打造了一套高效的進銷存管理系統。 系統不僅具備強大的庫存管理功能,還集成了高性能的輕量級 POS 解決方案,確保頁面載入速度極快,提供良好的用戶體驗。 項目介紹 Dorisoy.POS 是一款基於 .NET 7 和 Angular 4 開發的新零售快消進銷存管理 ...
  • ABP CLI常用的代碼分享 一、確保環境配置正確 安裝.NET CLI: ABP CLI是基於.NET Core或.NET 5/6/7等更高版本構建的,因此首先需要在你的開發環境中安裝.NET CLI。這可以通過訪問Microsoft官網下載並安裝相應版本的.NET SDK來實現。 安裝ABP ...
  • 問題 問題是這樣的:第三方的webapi,需要先調用登陸介面獲取Cookie,訪問其它介面時攜帶Cookie信息。 但使用HttpClient類調用登陸介面,返回的Headers中沒有找到Cookie信息。 分析 首先,使用Postman測試該登陸介面,正常返回Cookie信息,說明是HttpCli ...
  • 國內文章 關於.NET在中國為什麼工資低的分析 https://www.cnblogs.com/thinkingmore/p/18406244 .NET在中國開發者的薪資偏低,主要因市場需求、技術棧選擇和企業文化等因素所致。歷史上,.NET曾因微軟的閉源策略發展受限,儘管後來推出了跨平臺的.NET ...
  • 在WPF開發應用中,動畫不僅可以引起用戶的註意與興趣,而且還使軟體更加便於使用。前面幾篇文章講解了畫筆(Brush),形狀(Shape),幾何圖形(Geometry),變換(Transform)等相關內容,今天繼續講解動畫相關內容和知識點,僅供學習分享使用,如有不足之處,還請指正。 ...
  • 什麼是委托? 委托可以說是把一個方法代入另一個方法執行,相當於指向函數的指針;事件就相當於保存委托的數組; 1.實例化委托的方式: 方式1:通過new創建實例: public delegate void ShowDelegate(); 或者 public delegate string ShowDe ...