Oracle Character Set garbled solution-two common methods for reading and writing Oracle databases in. Net: oracleclient and oledb

Source: Internet
Author: User
Http://blog.csdn.net/lizhenhuatop/archive/2008/09/27/2986303.aspxFYI
For historical reasons, Oracle had no Chinese character sets (such as oracle6, oracle7, and oracle7.1), but some users used the database since then, and
You can use the us7ascii character set to store Chinese characters, or you may choose a default character set, such as we8iso8859p1 or
Us7ascii, and these two character sets do not have Chinese character encoding. Although this character set can be used normally sometimes, it is wrong to use this character set to store Chinese character information.
It brings a series of troubles to the use and maintenance of databases. Under normal circumstances, to save Chinese characters to the database, the database character set must support Chinese characters, and the database character set must be set to single-byte characters such as us7ascii.
Character Set is not suitable. The us7ascii character set defines only 128 characters and does not support Chinese characters.
In addition, if you can enter Chinese Characters in SQL * Plus, the operating system defaults
It should support Chinese characters, but if the character set in nls_lang is set to us7ascii, it is obviously incorrect and does not reflect the actual situation of the client. However, in practice, Chinese characters are displayed
But it is correct. This is mainly because Oracle checks the character set settings of the database and the client, so the data will not be converted during the access process between the customer and the database, but this is actually
As a result, the character set of the database identifier does not match the actually saved content. In the select process, Oracle also checks and finds that the character set settings of the database and the client are the same, so it
The stored content is also transmitted to the client intact, and the client operating system recognizes that this is a Chinese character encoding, so it can be correctly displayed.
In this example, neither the database nor the client is set to a Chinese character set, but the Chinese character set can be displayed normally. From the application perspective, it seems that there is no problem. However, there are great risks, such as unexpected results when applying string functions such as length or substr.
Pair
In the early days, data from us7ascii Character Set databases was migrated to Oracle8i/9I (zhs16gbk was used). Because the raw data has been saved in us7ascii format
In this case, you can use the Oracle8i export tool to set the export character set to us7ascii. After export, use ultraedit and other tools to open the DMP file and repair
Change the second and third characters to 0001 to 0354, so that the data of the us7ascii character set can be correctly imported into the database of zhs16gbk. To sum up, there are two common methods for reading and writing Oracle databases in. Net: oracleclient and oledb. oledb supports two methods based on different drivers.

 
1. oracleclient is developed by Microsoft for Oracle databases only in. NET Framework 1.1.
Supported. It is said that high speed and good performance are recommended. However, based on my experience, when the Oracle database server uses English character sets such as us7ascii
No matter how the character set is set, the client reads garbled characters in Chinese. If the server uses a Chinese character set such as zhs16gbk, there is no garbled problem.
Reference Class Library: system. Data. oracleclient. dll.
Namespace: system. Data. oracleclient.
Common classes: oracleconnection, oraclecommand, oracledataadapter, oracletransaction, and oracledatareader.
Typical connection string: "Data Source = oratest; user id = Scott; Password = tiger" (Note: do not specify the provider driver ).

2. In oledb mode, Microsoft and Oracle companies provide their own oledb drivers, with few differences in usage methods. No matter what character set is used on the Oracle server, there is no garbled problem in reading/writing Chinese characters.
Similarities
Namespace: system. Data. oledb.
Common classes: oledbconnection, oledbcommand, oledbdataadapter, oledbtransaction, and oledbdatareader.
Differences
Reference Class Library: Microsoft only needs system. data. DLL; if you use the Oracle driver, you only need to introduce the system. data. DLL, but the premise is that the first installation of Oracle.. NET data access component


.
Connection string: Compared with the oracleclient method, you need to add a provider, Microsoft is "provider = msdaora.1;", Oracle is "provider = 'oraoledb. oracle ';". Set conn = server. Createobject ("ADODB. Connection ")
DNS = "provider = oraoledb. oracle.1; persist Security info = true; user id = user1; Password = pass1; Data Source = oradb"

__________________

 

 

 

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.