This problem is I just stepped into the job feel the most pit of a problem, find a lot of methods, also asked many people, but still can not solve, accidentally back to the new world ....
The specific problem description is this:
I can read the existing Chinese content in the Oracle database and display it correctly (Chinese through sqlplus in Oracle), but when I use a C # program to insert Chinese records, I find that the database is garbled and read garbled. I tried a lot of coding, and the problem couldn't be solved.
Here are the solutions to find the relevant information:
The main problem is that the character encoding of the Oracle client software is inconsistent with the character encoding on the server side .
Oracle's character encoding is ZHS16GBK
Encoding.default is "GB2312" in C #
The Oracle service-side character encoding is: ZHS16GBK
The Oracle client character encoding is: WE8ISO8859P1
There are three ways to solve the problem:
(1) Modify the Client registry: Locate the Nls_lang under Oracle installation registration and change its value to "simplified Chinese_china. Zhs16gbk
(2) Set the code in the program by calling the _PUTENV function:
Using System.Runtime.InteropServices;
...
[DllImport ("Msvcrt.dll")]
private static extern int _putenv (string str);
...
_putenv ("Nls_lang = simplified Chinese_china. ZHS16GBK ");
Database operations
_putenv ("Nls_lang = American_amrica. We8iso8859p1 ");
(3) Setting environment variables by using C # 's own functions
System.Environment.SetEnvironmentVarible ("Nls_lang", "Simplified Chinese_china". ZHS16GBK ");
Database operations
System.Environment.SetEnvironmentVarible ("Nls_lang", "American_amrica". We8iso8859p1 ");
It is important to note that the second to third operation to set environment variables using functions must be outside the database operation to take effect.
Found to participate in the work, their own slowly like the blog park, every few days habitual all go in to see, see to their own help immediately to the collection, met with doubts will boldly questioned, here is really a good platform, is a programmer
Another one of the space. In this can meet a lot of big God, dick silk or cow b characters, I hope to grow together with you! The nonsense is not much, the study bit drops, all is worth sharing with everybody!