2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
👨 作者简介:大家好,我是Taro,全栈领域创作者
✒️ Personal homepage:Don Juan Taro
🚀 支持我:点赞👍+📝 评论 + ⭐️收藏
Recently, I was trying to connect to the hospital's HIS system and found that the hospital used Oracle'sAMERICAN_AMERICA.US7ASCIIThe encoding format is encoded, resulting in garbled Chinese data read into the program
以下是本篇文章正文内容,下面案例可供参考
Because the hospital unit data encoding cannot be changed, we tested many methods and finally chose a more efficient processing method (ODAC + OleDbConnection) using an independent Oracle driver to process
Oracle.ManagedDataAccess.Client It is the most used package for connecting C# to Oracle database, and it is also the .NET data access library officially provided by Oracle, but it cannot solve the garbled problem
Must adoptSystem.Data.OleDb , it uses an independent oracle driver to process, which is the key to solving the Chinese garbled code
System.Data.OleDb Dependencies:
Core code:
<add connectionString="Provider=OraOLEDB.Oracle;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=ORCL)));User ID=db;Password=db;" name="HIS" />
Program call:
下载ODAC :https://www.oracle.com/database/technologies/dotnet-utilsoft-downloads.html
After installing ODAC, you must restart your computer
Keep clicking "Next" until the installation is complete.
This step is to keep the local and client database character sets consistent, to prevent garbled characters when viewing data locally
变量名:NLS_LANG | 变量值:AMERICAN_AMERICA.US7ASCII
The code is as follows (example):
The above is what I want to talk about today. Due to historical reasons, the early Oracle did not have a Chinese character set (such as Oracle6, Oracle7, Oracle7.1), but some users have used the database since then and stored Chinese with the US7ASCII character set. This article only briefly introduces the use of the System.Data.OleDb library, which perfectly solves the Chinese garbled problem of the US7ASCII character set Oracle database.