在 C# 中使用 IBM Informix ODBC 驱动程序查询问题
Queries problems using IBM Informix ODBC Driver in C#
我在网上搜索了很多次关于我的问题后提出了我的问题。
为了我的工作,我需要使用 IBM Informix ODBC 驱动程序 (v 3.70) 在 C# 中对 Informix 数据库进行查询。
引擎的数据库 return 当我想提取字符 Ø (直径) 时 "ERROR [HY000] Invalid byte in codeset conversion input" 以下消息
我认为 DB_LOCALE 或 CLIENT_LOCALE 不匹配,但我不确定。
区域设置:
- DB_LOCALE : en_US.1252
- LIENT_LOCALE : en_US.1252
预先感谢您的帮助。
仔细检查数据库是否为 1252,以及 table 中的内容。
也许数据库中该特定字符的代码在 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>
也许 table 中的数据并非真正来自 1252。使用 CLIENT_LOCALE=DB_LOCALE 执行卸载或 dbexport(因此没有完成 GLS 转换)并检查如果 Ø 是 0xd8 或 0xF8 (upper/lower) 如果不是,则意味着 'Ø' 没有使用正确的语言环境插入。
编辑:
如果您在 table 中有一个 0x9D,您可能使用 850 而不是 1252 作为您的客户端代码集。
在 850 中(在某些 windows 中是 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>
如果 table 中有:
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>
我在网上搜索了很多次关于我的问题后提出了我的问题。
为了我的工作,我需要使用 IBM Informix ODBC 驱动程序 (v 3.70) 在 C# 中对 Informix 数据库进行查询。 引擎的数据库 return 当我想提取字符 Ø (直径) 时 "ERROR [HY000] Invalid byte in codeset conversion input" 以下消息
我认为 DB_LOCALE 或 CLIENT_LOCALE 不匹配,但我不确定。
区域设置: - DB_LOCALE : en_US.1252 - LIENT_LOCALE : en_US.1252
预先感谢您的帮助。
仔细检查数据库是否为 1252,以及 table 中的内容。 也许数据库中该特定字符的代码在 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>
也许 table 中的数据并非真正来自 1252。使用 CLIENT_LOCALE=DB_LOCALE 执行卸载或 dbexport(因此没有完成 GLS 转换)并检查如果 Ø 是 0xd8 或 0xF8 (upper/lower) 如果不是,则意味着 'Ø' 没有使用正确的语言环境插入。
编辑:
如果您在 table 中有一个 0x9D,您可能使用 850 而不是 1252 作为您的客户端代码集。 在 850 中(在某些 windows 中是 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>
如果 table 中有:
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>