仔细检查数据库是否为 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>cat s.cs
using System;
using System.IO;
using System.Data;
using System.Text;
using IBM.Data.Informix;
using System.Windows.Forms;
class sample {
static void Main(string[] args) {
try
{
using (IfxConnection conn = new IfxConnection("Server=ids1210;Database=enus1252;uid=informix;pwd=ximrofni;DB_LOCALE=en_US.1252"))
{
conn.Open();
using (IfxCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "select * from t1";
IfxDataReader rd = cmd.ExecuteReader();
rd.Read();
do
{
if (rd.HasRows)
Console.WriteLine("c1= {0}", rd[0]);
} while (rd.Read());
}
}
}
catch (IfxException exc)
{
Console.WriteLine("Update: {0}", exc.Message);
foreach (IfxError error in exc.Errors)
Console.WriteLine("Error: ({1}): {0}", error.Message, error.NativeError);
}
}
}
D:\Infx\work\cs>csc.exe /R:D:\infx\csdk410tc8w2\bin\netf20\IBM.Data.Informix.dll /nologo s.cs /platform:x86
两个字符都按原样返回:
D:\Infx\work\cs>s
c1= Øø
D:\Infx\work\cs>
也许表中的数据并不是真正来自 1252。使用 CLIENT_LOCALE=DB_LOCALE 执行卸载或 dbexport(因此没有完成 GLS 转换)并检查 Ø 是 0xd8 还是 0xF8(上/下)如果是不是,这意味着没有使用正确的语言环境插入“Ø”。
编辑:
如果表中有 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 转换(0x9D 不应该在 1252 中使用)
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>