C#/Oracle: Specify Encoding/Character Set of Query?

血红的双手。 提交于 2019-12-02 03:35:46
lsk

you can also add Unicode=true in your connection string

It was a Problem with my OracleConnection:

var oracleConnection = new OracleConnection(connectionString);
oracleConnection.Open();
return oracleConnection;

This fixed it:

oracleConnection.Unicode = true;

(before opening the connection)

By the way: I'm using the DevArt's ADO.NET Provider for Oracle

.Net CLR strings are [internally] UTF-16 encoded. ADO.Net, at least with SQL Server, handles the translation between the native string format in the database and the UTF-16 encoding used in the .Net CLR.

I suspect that that's true with Oracle's ADO.Net provider as well.

However, Console.WriteLine() is doing its own thing. You can get (or set) the input encoding via Console.InputEncoding and get/set the output encoding via Console.OutputEncoding.

On my machine, Console.WriteLine() displays accented characters properly. The default output encoding on my machine is System.Text.SBCSCodePageEncoding. It's using the IBM 437 aka Windows 1252 code page. And it's using the default raster font 'Terminal'.

If the font your are using doesn't support (at least) the C0 Control and Basic Latin and C1 Controls and Latin-1 Supplement (ISO 8859-1), you're unlikely to have success with accented characters. the IBM 437/Windows 1252 code page is mostly ISO 8859-1, except that code points 0x80 to 0x9F (the C1 control characters) have been assigned glyphs.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!