The information in this article applies to:
SUMMARY
This article explains code pages in SQL Server, and how inserting or
retrieving data is affected by enabling or disabling the AutoAnsiToOem
setting.
All of the Windows-based clients (such as Isql/w, SQL Enterprise Manager, Transfer Manager, SQL Administrator, and SQL Object Manager) are considered ANSI clients. MS-DOS or console-based applications such as Isql and BCP are considered OEM clients. The exception to this is the Transfer Data option of Object Manager, which behaves as an OEM client. A SQL Server with a code page of 1250 thru 1259 is considered to be an ANSI server, and a SQL Server with any other code page (for example, 850 or 437) is considered to be an OEM server. The OEM code page used to translate characters depends on the current OEM code page of the client's operating system. For example, with the AutoAnsiToOem option enabled, ASCII character 165 ([ASCII 165]) in an ANSI server gets converted to ASCII 190 ([ASCII 165]) when selecting from an OEM client with code page 850, and to ASCII 157 ([ASCII 165]) when selecting from an OEM client with code page 437. MORE INFORMATIONThe following table provides an overview for the rest of this article:
PART A: How to Determine the Code Page of SQL ServerThe stored procedure sp_helpsort can be used to find the SQL Server's sort order and character set.PART B: Enabling or Disabling AutoAnsiToOemThe registry entry AutoAnsiToOem can be enabled or disabled by selecting the Automatic ANSI to OEM check box in the client configuration utility. In SQL Server 4.21a, Automatic ANSI to OEM is disabled by default, whereas in versions 6.0 and 6.5 it is enabled by default.PART C: How to Check the Validity of the Data SavedThe Transact SQL string function ASCII(char_expr) can be used to determine what is actually saved on the server. This function shows the ASCII code value of the leftmost character in a character expression. For example, if you have character "[ASCII 177]" saved on an 850 server, selecting the data from Isql/w may show you character "[ASCII 177]" (when AutoAnsiToOem is on) or "[ASCII 241]" (when AutoAnsiToOem is off). However, selecting ASCII(<column_name>) will show you 241 (which is "[ASCII 177]" on 850 code page).PART D: What Happens when a Character on One Code Page is Unavailable on AnotherIf a conversion occurs and a character on one code page is unavailable on another, the character gets converted to its closest equivalent character on the other code page. For example, ASCII 224 ("alpha") on code page 437 is converted to 97("a") on the ANSI code page. When you convert it back to code page 437, you receive 97("a"). This is a problem, because you have now lost the original 224("alpha"). This can potentially cause incorrect data to be saved on your server, as happens in the following two examples:Example 1: You have an OEM server in which you are inserting data from an ANSI client, and your AutoAnsiToOem option is enabled. If the character that you are inserting is valid in both code pages, the correct data will be saved. However, if the character is valid in ANSI but not in OEM, the correct data will not be saved. Example 2: You insert data into an ANSI server from an OEM client, and the AutoAnsiToOem option is enabled. If the character that you are inserting is valid in both code pages, the correct data will be saved. However, if the character is valid in OEM and not in ANSI, then correct data will not be saved. PART E: Entering Extended Characters with a U.S. KeyboardPress NUMLOCK and use the numeric keypad on the right side of the keyboard. To enter ANSI extended characters, hold the ALT key and then type the ASCII code of the character preceded by a zero (0). To enter OEM extended characters, hold the ALT key and type just the ASCII code of the character. For example, to enter +, hold ALT and type 0165, or type 157 (if the client's OEM code page is 437), or type 190 (if the client's OEM code page is 850).PART F: How to Change the OEM Code Page of Windows NT and Windows 95For Windows NT 3.51, the preferred method of changing the OEM code page in Windows NT is to change the language in Control Panel International. For Windows NT 4.0 or Windows 95, the OEM code page is chosen during initial setup.Additionally, The OEM code page can be changed by changing the OEMCP and OEMHAL (Windows NT only) registry values in the following location:
These changes take effect after rebooting Windows NT or Windows 95.
The OEMCP value controls to which OEM code page to translate ANSI, and the OEMHAL value controls the display of extended characters at a command prompt. Some of the possible values for these registry values are:
In addition to changing the OEMCP registry value, this setting also changes the OEMHAL value, which controls the display of extended characters at a command prompt. PART G: How to Change OEM Code Page of MS-DOS and Windows 3.xTo change the code page for MS-DOS, refer to Chapter 6, National Language Support in the MS-DOS Programming Reference 6.0. Once the MS-DOS code page is changed, you must run the Windows Setup program to change its ANSI-OEM translation tables for ANSI to OEM conversion.PART H: Client Suggestions for Consistent DataThe following suggestions will help to ensure that the data stored on the SQL Server is stored according to the SQL Server code page rather than the client's code page, which is usually the cause of bad data.MS-DOS clients: Since MS-DOS only has an OEM code page and no ANSI code page, no conversions are made. The client will always store data on the server with the client's OEM code page, so the code page of SQL Server should be set to match the client's code page. OEM and ANSI clients: If the computer running SQL Server is not using the ANSI code page, change the client's OEM code page to match the SQL Server code page and enable the AutoAnsiToOem conversion. If the computer running SQL Server is using the ANSI code page, just enable the AutoAnsiToOem conversion. The following are exceptions to the above suggestions:
PART I: MS-DOS Isql.exe ExamplesThe tables in each of the following examples show the decimal equivalents of the character at various points.INSERT and SELECT of the + character with the MS-DOS Isql.exe client with a 437 OEM code page into and from a 437 code page SQL Server.
* The value never changes from 157, since MS-DOS clients do not perform AnsiToOem conversions. PART J: Win32 Bcp.exe ExamplesExample 1:EXPORT and IMPORT of the + character Win32 Bcp.exe client with an 850 OEM code page into an 850 code page SQL Server.
* Because both the client and server are OEM, no conversion is performed. Example 2: IMPORT of + character Win32 Bcp.exe client with a 437 OEM code page, and data created with code page 437, into an ANSI code page SQL Server.
* + converted to ANSI equivalent. Example 3: EXPORT of 165 character Win32 Bcp.exe client with a 437 OEM code page, from an ANSI code page SQL Server, to import later into a 437 code page SQL Server.
* + converted back to OEM equivalent. Example 4: EXPORT of + character Win32 Bcp.exe client with a 1252 OEM code page, from an ANSI code page SQL Server to import later into the same SQL Server.
* Because the ANSI code page matches the OEM code page on the client, no conversion occurs. PART K: Isqlw.exe ExamplesExample 1:INSERT and SELECT of Win16 or Win32 Isqlw.exe client into an ANSI code page SQL Server.
* Because both the client and server are ANSI, no conversion is performed. Example 2: INSERT and SELECT of Win16 or Win32 ISQLW.EXE client with OEM code page 437 into a 437 code page SQL Server.
* [ASCII 165] converted to OEM equivalent. ** [ASCII 165] converted to ANSI equivalent. PART L: Transfer Manager ExamplesExample 1:SQL Server Transfer Manager 6.0 between two ANSI code page SQL Servers.
* Because both the client and server are ANSI, no conversion is performed. Example 2: SQL Server Transfer Manager 6.0 with OEM code page 437, from a 437 code page SQL Server to an ANSI code page SQL Server.
* [ASCII 165] converted to ANSI equivalent. ** Because both the client and server are ANSI no conversion is performed. Example 3: SQL Server Transfer Manager 6.0 with OEM code page 850, from an ANSI code page SQL Server to an 850 code page SQL Server.
* Because both the client and server are ANSI no conversion is performed. ** [ASCII 165] converted to OEM equivalent. Example 4: SQL Server Transfer Manager 6.0 with OEM code page 850, from an 850 code page SQL Server to an 850 code page SQL Server.
* [ASCII 165] converted to ANSI equivalent. ** [ASCII 165] converted to OEM equivalent. PART M: ODBC and ANSI to OEM ConversionsAll ODBC clients (GUI and console applications) are ANSI clients as defined by the ODBC specification. Translation will only occur with non-ANSI code page SQL Servers. ODBC clients have three translation choices: no translation, translate with OEM code page, or use an ODBC Code Page Translator. Translation with the OEM code page works the same as DB-Library ANSI to OEM conversion, in that the OEM code page of the client determines what is stored on the server. This option is chosen by selecting the ConvertOEM to ANSI characters check box in the Datasource Setup dialog box. To use an ODBC Code Page Translator, click the Select button in the Translation section of the Datasource Setup dialog box, click the MS Code Page translator, and then select the code page translator to use. This option overrides the Convert OEM to ANSI characters check box and does the OEM translation according to the translator chosen, instead of the OEM code page. All ODBC clients are ANSI clients, and translation will only occur with non-ANSI code page SQLservers.PART N: MS-Query ODBC Client ExamplesExample 1:SELECT of MS-Query client from an ANSI code page SQL Server.
* Since both client and server are ANSI, no conversion is performed no matter which translation is chosen. Example 2: SELECT of MS-Query client with OEM code page 437, and Convert OEM to ANSI character enabled, from a 437 code page SQL Server.
* Converted to ANSI equivalent. Example 3: SELECT of MS-Query client with OEM code page 437, Convert OEM to ANSI character enabled, and the Windows Latin 1(1252)/850 (Multilingual- Latin 1) MS Code Page translator from a 850 code page SQL Server.
* Converted to ANSI equivalent using 850 OEM code page due to translator. PART O: Other Related Code Page ArticlesFor more information on code pages and the AnsiToOem option, please see the following articles in the Microsoft Knowledge Base:Q75435 - Windows, Code Pages, and Character Sets Q152980 - BUG: AnsiToOem Check Box Does Not Work in 6.0 Transfer Manager Additional query words: OemToChar
Keywords : kbusage SSrvGen |
Last Reviewed: February 18, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |