对 Informix 串行和 BigInt 数据类型的 ODBC 支持
我的服务器上安装了 Informix Dynamic Server 11.50 和 Informix Client SDK 3.5。我正在开发一个 .NET 应用程序来使用 ODBC 函数从 Informix 数据库读取数据。
在数据库中,我有一个表,其中定义了 Serial 和 BigInt 数据类型的列。我的数据检索功能如下所示。
Dim cmd As New Odbc.OdbcCommand
Dim da As New Odbc.OdbcDataAdapter
Dim ds As New DataSet
Dim sb As New StringBuilder("")
Try
Using cn As New Odbc.OdbcConnection(ConfigurationSettings.AppSettings("connString"))
cn.Open()
sb.Append("SELECT * FROM InterfaceSP ")
sb.Append("join Interface on InterfaceSP.InterfaceID = Interface.InterfaceID ")
sb.Append("left join InterfaceSPAction on InterfaceSP.InterfaceSPID = InterfaceSPAction.InterfaceSPID and action_status = 'ACTV' ")
sb.Append(" WHERE InterfaceSP.InterfaceID = ? ")
sb.Append(" ORDER BY InterfaceSP.SPName")
cmd.Connection = cn
cmd.CommandType = CommandType.Text
cmd.CommandText = sb.ToString
cmd.Parameters.AddWithValue("@InterfaceID", strInterfaceID)
da.SelectCommand = cmd
da.Fill(ds, "InterfaceSPList")
End Using
Return ds
Catch ex As Exception
Throw ex
End Try
最终结果数据集将传递给数据网格对象。问题是每当加载数据网格时 .NET 都会引发异常。
Unknown SQL type - -114.
[ArgumentException: Unknown SQL type - -114.]
我尝试将具有 Serial 和 BigInt 数据类型的列修改为 Integer。而且,无需修改任何一行代码,一切都可以正常工作。
我确实需要一些建议来解决这个问题,因为我需要串行数据类型列作为递增的 id 列。对于 BigInt 数据类型列,也许我们可以将其更改为 Integer 数据类型列。
欢迎任何建议。
I have Informix Dynamic Server 11.50 and Informix Client SDK 3.5 installed on my server. I am developing a .NET application to read data from Informix database using ODBC functions.
In the database, i have a table with columns of Serial and BigInt data types defined. My data retrieve function looks like this.
Dim cmd As New Odbc.OdbcCommand
Dim da As New Odbc.OdbcDataAdapter
Dim ds As New DataSet
Dim sb As New StringBuilder("")
Try
Using cn As New Odbc.OdbcConnection(ConfigurationSettings.AppSettings("connString"))
cn.Open()
sb.Append("SELECT * FROM InterfaceSP ")
sb.Append("join Interface on InterfaceSP.InterfaceID = Interface.InterfaceID ")
sb.Append("left join InterfaceSPAction on InterfaceSP.InterfaceSPID = InterfaceSPAction.InterfaceSPID and action_status = 'ACTV' ")
sb.Append(" WHERE InterfaceSP.InterfaceID = ? ")
sb.Append(" ORDER BY InterfaceSP.SPName")
cmd.Connection = cn
cmd.CommandType = CommandType.Text
cmd.CommandText = sb.ToString
cmd.Parameters.AddWithValue("@InterfaceID", strInterfaceID)
da.SelectCommand = cmd
da.Fill(ds, "InterfaceSPList")
End Using
Return ds
Catch ex As Exception
Throw ex
End Try
The end result dataset will be passed to a datagrid object. The problem is .NET throws an exception whenever the datagrid is loaded.
Unknown SQL type - -114.
[ArgumentException: Unknown SQL type - -114.]
I've tried to modify the columns with Serial and BigInt data types to Integer. And, everything works fine without modifying a single line of code.
I do need some advice how to overcome this problem as i need the Serial data type column as an incrementing id column. For BigInt data type column, may be we can change it to column with Integer data type instead.
Any advice is welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
.NET“了解”一组有限的数据类型。从各种数据源检索数据的 .NET 数据提供程序必须将各种数据类型转换为 .NET 可以识别的类型。 ODBC .NET 数据提供程序内置了一定数量的可识别类型。该集合之外的任何内容都可能导致错误。
为了解决这个问题,我怀疑您可以在运行的 SQL SELECT 语句中转换数据类型。我对 Informix 不熟悉,但简单的谷歌搜索似乎表明转换是使用这种格式
columnname::newtype
完成的。因此,您需要将 SELECT 语句中的*
替换为特定字段,然后将有问题的列转换为可识别的类型,例如整数:SerialCol::Integer
。 (我猜测类型)。.NET "knows" about a finite set of data types. The .NET data providers that retrieve data from various data sources must convert the various data types to something that .NET recognizes. The ODBC .NET data provider has a certain number of recognized types built into it. Anything outside that set can result in an error.
To get around this, I suspect you can cast the data type in the SQL SELECT statement that you run. I am not familiar with Informix, but a brief bit of googling seems to indicate that a cast is done with this format
columnname::newtype
. So you will need to replace the*
in the SELECT statement with the specific fields and then cast the problematic columns to a recognized type such as integer:SerialCol::Integer
. (I'm guessing at the type).需要查看您的 CLIENT_locale 和连接字符串的 DB_locale 设置
need to look at your CLIENT_locale and the DB_locale settings of your connection string