簡體   English   中英

C#.net Core和Oracle設置編碼

[英]C# .net Core and Oracle set encoding

.Net Core上的web-api項目中,已通過dotNetCore.data.OracleClient (nugget package)連接到Oracle DB。

我從流水線函數讀取數據,如下所示:

 using (DbConnection connection = new OracleConnection("oraclecs")) {
    connection.Open();

    using (var cmd = connection.CreateCommand()) {
      cmd.CommandType = CommandType.Text;

      cmd.CommandText = "select name from Table(SCHEMA.PACKAGE.FUNC(PARAM1=>1,PARAM2=>4))";

      DbDataReader er = cmd.ExecuteReader();
      while (er.Read()) {
        string Name = er.GetValue(er.GetOrdinal(name: "name")).ToString();
      }
      connection.Close();
    }
  }

數據庫中使用俄語DB編碼為NLS_CHARACTERSET數據庫的名稱為CL8MSWIN1251

當我從字段name獲得價值時,我看到了????????? 代替真實姓名

也只需通過Oracle SQL Developer在命令文本中select返回正確的數據

有什么可以幫助我解決它?

感謝您對@ wernfried-domscheit的幫助

我的.net Core Web-api在docker中運行

我在docker-compose.override.yml文件中設置了NLS_LANG = .CL8MSWIN1251,這對我有所幫助

我的docker-compose.override.yml文件:

version: '3'

services:
  api:
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
      - ORACLE_CS=Data Source = ip:port/sid;PERSIST SECURITY INFO=True;USER ID=user; Password=password;
      - NLS_LANG=.CL8MSWIN1251
    ports:
      - "5050:80"
networks:
  default:
    external:
      name: nat

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM