Firebird ADO.NET问题,从FbDataAdapter加载数据集
我的商业网站上有几个免费的数据访问层。我一直在他们的网站上关注Firebird数据库,现在决定为这个数据库引擎建立一个新的数据访问层。Firebird ADO.NET问题,从FbDataAdapter加载数据集
我正在使用Firebird网站上推荐的ADO.NET提供程序(https://www.firebirdsql.org/en/net-provider/)。正在使用的版本是5.5。
我开发了一个简单的存储过程来处理返回的几列数据,这些数据列已经在我的数据库管理器中成功测试过了。它也已经在我为我的Firebird数据访问层构建的测试客户端中用数据读取器成功测试过。
然而,当我试图对测试数据集的回报存储过程,我一直收到以下错误......
无法投类型的对象“System.String”输入'System.Byte []'
即使使用参数进行简单的内联查询也会产生相同的错误。
然而,这些非常相同的测试与我的数据阅读器进程正常工作。
当我在代码中填充Firebird数据适配器中的数据集时,总是会出现此错误。
我测试的代码如下
Public Overloads Function ExecuteDataSet(ByVal psConnectionString As String, _
ByVal psQuery As String, _
ByRef poParameterStructures As ArrayList) As DataSet
Dim loParameterStructures As New ArrayList()
Dim loDataSet As DataSet
Dim loFbSqlConnection As FbConnection = Nothing
Dim loFbSqlParameter As FbParameter
Dim loFbSqlCommand As FbCommand = Nothing
Dim loFbSqlDataAdapter As FbDataAdapter = Nothing
Try
'DataTable dt = new DataTable();
'FbDataAdapter da = new FbDataAdapter("select_mytable", ConfigurationManager.ConnectionStrings["mydb"].ConnectionString);
'da.SelectCommand.CommandType = CommandType.StoredProcedure;
'da.SelectCommand.Parameters.Add("@id", 123);
'da.Fill(dt);
loFbSqlConnection = Get_DBConnection(psConnectionString)
loFbSqlCommand = New FbCommand(psQuery, loFbSqlConnection)
loFbSqlCommand.CommandTimeout = ciTimeOut
' check for parameterized inline SQL or stored-procedure
If ((psQuery.IndexOf("@") > -1) Or _
(psQuery.ToUpper().IndexOf("SELECT ") > -1)) Then
loFbSqlCommand.CommandType = CommandType.Text
Else
loFbSqlCommand.CommandType = CommandType.StoredProcedure
End If
' create parameters for stored-procedure
If (Not poParameterStructures Is Nothing) Then
For Each loFbSqlHelperParameterStructure As FbSqlHelperParameterStructure In poParameterStructures
loFbSqlParameter = New FbParameter()
loFbSqlParameter.ParameterName = loFbSqlHelperParameterStructure.PARAMETER_NAME
loFbSqlParameter.DbType = loFbSqlHelperParameterStructure.PARAMETER_FBSQLDBTYPE
loFbSqlParameter.Direction = loFbSqlHelperParameterStructure.PARAMETER_DIRECTION
Select Case loFbSqlParameter.Direction
Case ParameterDirection.Input:
loFbSqlParameter.Value = loFbSqlHelperParameterStructure.PARAMETER_VALUE
loFbSqlParameter.Size = loFbSqlHelperParameterStructure.PARAMETER_SIZE
Case ParameterDirection.Output:
loFbSqlParameter.Size = loFbSqlHelperParameterStructure.PARAMETER_SIZE
End Select
loFbSqlCommand.Parameters.Add(loFbSqlParameter)
Next
End If
loFbSqlDataAdapter = New FbDataAdapter()
loFbSqlDataAdapter.SelectCommand = loFbSqlCommand
loDataSet = New DataSet()
loFbSqlDataAdapter.Fill(loDataSet)
Catch loFbSqlException As FbException
Throw loFbSqlException
Catch loException As Exception
Throw loException
Finally
loFbSqlCommand.Dispose()
loFbSqlConnection.Close()
loFbSqlConnection.Dispose()
End Try
poParameterStructures = loParameterStructures
Return (loDataSet)
End Function
上面还与支持SQL Server,SQL Server的CE时,MySQL和PostgreSQL我的其他数据访问层已成功使用的代码。
但是,就Firebird数据库而言,无论从Firebird数据库中获取数据集的所有文档中的代码设置如何,都会产生与上述完全相同的错误。因此,此处提供的代码是在其他数据访问层中成功使用的原始代码。
我终于找到上面的代码中的问题...
如果你在我的“最后”的语句,你会看到下面的代码行...看看“loFbSqlCommand.Dispose()”
虽然,这行代码已被成功地在我分发其他数据访问层中使用,因为它破坏了引用指针链向上进入返回的数据集,这是从FbDataAdapter一个完全独立的对象火鸟ADO.NET数据提供者。
删除此行的代码或注释掉和代码工作正常。
你可以在http://tracker.firebirdsql.org/browse/DNET上提交一个bug,因为这听起来不像是应该发生的事情。 –