Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
linux上C#.net内核中odbc编码的问题_C#_Linux_.net Core_Encoding_Odbc - Fatal编程技术网

linux上C#.net内核中odbc编码的问题

linux上C#.net内核中odbc编码的问题,c#,linux,.net-core,encoding,odbc,C#,Linux,.net Core,Encoding,Odbc,我正在linux下编写一个C#程序,并尝试使用ODBC连接到数据库。数据库是WIN1251编码的,我用问号代替字符 操作系统:Ubuntu 数据库:Interbase 框架版本:.net core 5.0 我试图解决这个问题: ODBC驱动程序工作正常,使用来自控制台LANG=ru_-ru的命令。CP1251 luit isql-v DEVART_INTERBASE(使用WIN1251编码运行,连接参数完全相同)我执行了数据库访问,所有字符都正常显示 将string login=(string)

我正在linux下编写一个C#程序,并尝试使用ODBC连接到数据库。数据库是WIN1251编码的,我用问号代替字符

操作系统:Ubuntu

数据库:Interbase

框架版本:.net core 5.0

我试图解决这个问题:

  • ODBC驱动程序工作正常,使用来自控制台LANG=ru_-ru的命令。CP1251 luit isql-v DEVART_INTERBASE(使用WIN1251编码运行,连接参数完全相同)我执行了数据库访问,所有字符都正常显示
  • string login=(string)读卡器[“login”]
    替换为
  • 同样,所有字符都正常显示。我本可以使用这种方法,但当我在数据库中使用INSERT或UPDATE命令时,非英语字符写得不正确,我不知道如何解决这个问题

  • windows上的类似代码可以正常工作
  • 我很乐意接受任何建议

    using System;
    using System.Data.Odbc;
    
    namespace net_core {
        class Program {
    
            static void Main(string[] args) {
                OdbcConnection connection = new OdbcConnection("DRIVER={Devart ODBC Driver for InterBase};Server=10.0.2.2;Database=D:\\InterBase\\gdb\\DATABASE.GDB;Port=3050;User ID=SYSDBA;Password=masterkey;Client Library=/usr/local/lib/libgds.so;Charset=win1251;CharacterSet=win1251;Dialect=3");
                connection.Open();
    
                var command = connection.CreateCommand();
                command.CommandText="SELECT LOGIN FROM USERS";
                OdbcDataReader reader = command.ExecuteReader();
                reader.Read();
                string login = (string)reader["LOGIN"];
                Console.WriteLine(login);
            }
        }
    }
    

    如果它在Windows上正常工作,但在Linux上不正常,那么它可能是一个bug…您如何查看结果。问题可能只是您用来查看结果的工具。若你们在linux中写,你们能从数据库中正确地读入窗口吗?我把结果写到控制台。在调试视图中,结果也是一样的。我认为,odbc工具使用错误的编码器对文本进行编码/解码,但我如何设置正确的编码器?如果它在Windows上正常工作,但在Linux上不正常,则可能是一个错误…您如何查看结果。问题可能只是您用来查看结果的工具。若你们在linux中写,你们能从数据库中正确地读入窗口吗?我把结果写到控制台。我想,odbc工具使用了错误的编码器对文本进行编码/解码,但如何设置正确的编码器呢?
    using System;
    using System.Data.Odbc;
    
    namespace net_core {
        class Program {
    
            static void Main(string[] args) {
                OdbcConnection connection = new OdbcConnection("DRIVER={Devart ODBC Driver for InterBase};Server=10.0.2.2;Database=D:\\InterBase\\gdb\\DATABASE.GDB;Port=3050;User ID=SYSDBA;Password=masterkey;Client Library=/usr/local/lib/libgds.so;Charset=win1251;CharacterSet=win1251;Dialect=3");
                connection.Open();
    
                var command = connection.CreateCommand();
                command.CommandText="SELECT LOGIN FROM USERS";
                OdbcDataReader reader = command.ExecuteReader();
                reader.Read();
                string login = (string)reader["LOGIN"];
                Console.WriteLine(login);
            }
        }
    }