C# .net Core 和 Oracle 设置编码

C# .net Core and Oracle set encoding

.Net Core 上的 Web-api 项目已通过 dotNetCore.data.OracleClient (nugget package)

连接到 Oracle 数据库

我像这样从流水线函数中读取数据:

 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();
    }
  }

数据库中的俄语名称 数据库编码 NLS_CHARACTERSETCL8MSWIN1251

当我从字段 name 中获取值时,我看到了 ????????而不是真实姓名

也只是 select 在命令文本中通过 Oracle SQL Developer return 正确的数据

有什么可以帮我解决的?

感谢对@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