C# 在C中使用IBM Informix ODBC驱动程序查询问题#
我在网上多次搜索我的问题后提出了我的问题 为了完成我的工作,我需要使用IBMInformixODBC驱动程序(V3.70)在Informix数据库上用C#进行查询。 当我想要提取字符Ø(直径)时,引擎的数据库返回以下消息“错误[HY000]代码集转换输入中的无效字节” 我认为数据库语言环境或客户端语言环境不匹配,但我不确定 区域设置: -DB_地区:en_US.1252 -客户地点:en_US.1252C# 在C中使用IBM Informix ODBC驱动程序查询问题#,c#,informix,C#,Informix,我在网上多次搜索我的问题后提出了我的问题 为了完成我的工作,我需要使用IBMInformixODBC驱动程序(V3.70)在Informix数据库上用C#进行查询。 当我想要提取字符Ø(直径)时,引擎的数据库返回以下消息“错误[HY000]代码集转换输入中的无效字节” 我认为数据库语言环境或客户端语言环境不匹配,但我不确定 区域设置: -DB_地区:en_US.1252 -客户地点:en_US.1252 提前感谢您的帮助。再次检查数据库是否为1252,以及表中的内容。 可能数据库中该特定字符的代
提前感谢您的帮助。再次检查数据库是否为1252,以及表中的内容。 可能数据库中该特定字符的代码在CP1252中并不真正有效 在1252中,O形斜杠对应于:
Ø 0xd8 Latin Capital Letter O With Stroke
ø 0xf8 Latin Small Letter O with Stroke
使用1252数据库的快速测试:
D:\infx\ids12>set DB_LOCALE=en_US.1252
D:\infx\ids12>set CLIENT_LOCALE=en_US.1252
D:\infx\ids12>dbaccess enus1252 -
Database selected.
> drop table t1;
Table dropped.
> create table t1(c1 char(10));
Table created.
> load from o.txt insert into t1;
1 row(s) loaded.
>
Database closed.
D:\infx\ids12>od -x o.txt
0000000000 F8D8
0000000002
使用oncheck查看页面中真正的内容
D:\infx\ids12>oncheck -pp enus1252:t1 256
addr stamp chksum nslots flag type frptr frcnt next p
rev
1:16444 725726638 ded2 1 1 DATA 34 4054 0
0
slot ptr len flg
1 24 10 0
slot 1:
0: d8 f8 20 20 20 20 20 20 20 20 Xx ......
D:\infx\ids12>
现在来自C#
这两个字符按其应返回的方式返回:
D:\Infx\work\cs>s
c1= Øø
D:\Infx\work\cs>
也许表中的数据并非来自1252年。使用CLIENT_LOCALE=DB_LOCALE执行卸载或dbexport(因此没有进行GLS转换),并检查Ø是否为0xd8或0xF8(上/下)。如果不是,则表示没有使用正确的LOCALE插入“Ø”
编辑:
如果表中有0x9D,则可能使用850而不是1252作为客户端代码集。
在850(在某些窗口中是cmd的默认代码集)中,“Ø”是0x9D,而不是0xD8
D:\Infx>chcp 1252
Active code page: 1252
D:\Infx>echo Ø | od -x
0000000000 20D8 0A0D
0000000004
D:\Infx>chcp 850
Active code page: 850
D:\Infx>echo Ø | od -x
0000000000 209D 0A0D
0000000004
D:\Infx>
如果表中有:
D:\infx\ids12>dbaccess enus1252 -
Database selected.
> truncate t1;
Table truncated.
> insert into t1 values ('Ø');
1 row(s) inserted.
>
Database closed.
D:\infx\ids12>oncheck -pp enus1252:t1 256
addr stamp chksum nslots flag type frptr frcnt next p
rev
1:16444 725727918 d1d2 1 1 DATA 34 4054 0
0
slot ptr len flg
1 24 10 0
slot 1:
0: 9d 20 20 20 20 20 20 20 20 20 . ......
D:\infx\ids12>
C#将给您一个错误,因为存在从0x9D的转换(在1252中不应使用0x9D)
谢谢你的回复。这个命令oncheck-ppenus1252:t1256非常有用。问题不在于这个角色,而在于他面前的一片空白。在表中,我有十六进制代码0xD8和0xF8,还有0x9D,它们在我的区域设置中是未知字符。我删除了他们,现在一切都好了!很好,你成功了。通常开发人员在设置Informix数据库时只关心DB_语言环境,但客户端语言环境也非常重要。如果你弄错了,它将来可能会咬你;)
D:\infx\ids12>dbaccess enus1252 -
Database selected.
> truncate t1;
Table truncated.
> insert into t1 values ('Ø');
1 row(s) inserted.
>
Database closed.
D:\infx\ids12>oncheck -pp enus1252:t1 256
addr stamp chksum nslots flag type frptr frcnt next p
rev
1:16444 725727918 d1d2 1 1 DATA 34 4054 0
0
slot ptr len flg
1 24 10 0
slot 1:
0: 9d 20 20 20 20 20 20 20 20 20 . ......
D:\infx\ids12>
D:\Infx\work\cs>s
Update: ERROR [HY000] [Informix .NET provider]Invalid byte in codeset conversion input.
Error: (21000): [Informix .NET provider]Invalid byte in codeset conversion input.
D:\Infx\work\cs>