.net - OleDB 将 .NET 2.0 更改为 4.6.1 返回记录集
问题描述
我正在将一个旧的 VB 项目(在 C# 之前)从 .NET 2 升级到 4.6.1
重要的是要注意,这个项目对于数据库提供者是不可知的。它仅通过更改连接字符串来使用 SQL Server 或 Oracle。据推测,它将适用于任何其他 OleDB 数据源。因此,必须避免直接引用 Oracle 二进制文件。例如,下面是使用 Oracle 但我无法在源代码中引用 Oracle.anything。
这是我的问题:
这段代码在 .NET 2.0 下完美执行:
cmdDB.Transaction = transDB
cmdDB.CommandText = "myPackage.MyFunction"
cmdDB.CommandType = CommandType.StoredProcedure
cmdDB.Parameters.Add("p_extract_key", someValue)
cmdDB.Connection = conDB
Try
rdrDB = cmdDB.ExecuteReader(CommandBehavior.SingleRow)
Catch ex As Exception
Debug.WriteLine(ex.ToString)
Throw ex
End Try
```
Then it uses rdrDB to read the row
将“Parameters.Add”更改为“Parameters.AddValue”后,它针对 4.6.1 进行编译
但是,它因“PLS-00306:调用‘MyFunction’时参数的数量或类型错误”而失败
存储过程的签名如下所示:
TYPE outcur_type is REF CURSOR;
procedure OBJEX_PR_OFFICE(p_extract_key in varchar2, outcur out outcur_type);
“outcur”的类型为 REF_CURSOR
猜测现在需要我为光标提供一个 OUT 参数的重大更改,我在 Try 之前添加了这些代码行:
Dim outCursor As New OleDbParameter
outCursor.ParameterName = "outcur"
outCursor.Direction = ParameterDirection.Output
cmdDB.Parameters.Add(outCursor)
现在我们得到了这个:
Exception thrown: 'System.InvalidOperationException' in System.Data.dll
System.InvalidOperationException: String[1]: the Size property has an invalid size of 0.
at System.Data.OleDb.OleDbParameter.BindParameter(Int32 index, Bindings bindings)
at System.Data.OleDb.OleDbCommand.CreateAccessor()
at System.Data.OleDb.OleDbCommand.InitializeCommand(CommandBehavior behavior, Boolean throwifnotsupported)
at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)
我花了几个小时来研究各种参数值的组合。在我看来,将 outCursor 参数的 DbType 设置为类型 DbType.Cursor 或 OleDBType.Cursor 可能会有所帮助,但似乎不存在这样的类型。
我可以更改应用程序以定义接口并为不同的数据库提供程序创建实现并避免使用 OleDB。但在我通知我的客户他们的项目成本即将爆炸之前,我想我会向社区征求意见。
关于下一步该做什么的任何想法?
解决方案
推荐阅读
- reactjs - 从 React NavMenu 触发重定向会删除菜单
- sql - 从 VBA 中的 SQL 返回客户计数
- http - TypeError:通过 HTTP2 调用 204(无内容)和 304(未修改)的网络请求失败(Chrome 中的 ERR_HTTP2_PROTOCOL_ERROR)
- python - While 循环在应该中断时不会中断
- swift - SwiftUI:类型不符合协议“UIViewRepresentable”
- javascript - 检查mongodb中是否存在数字
- javascript - 如何在 create-react 应用程序上添加 Cache-Control
- javascript - 从不同的选择标签中选择值
- python - 使用调度程序,其中时间存储在列表中,函数的输入也存储在列表中
- generics - Grails TypeChecked / CompileStatic / GrailsCompileStatic