[英]How to fix “Multiple-stop OLE DB operation…” errors when using ADO Command to run stored procedure in SQL Server
I'm trying to run a SQL Server stored procedure that returns records using an ADO Command object. 我正在尝试运行一个SQL Server存储过程,该存储过程使用ADO Command对象返回记录。 I'm able to connect to the database (my connection is used elsewhere in my code and, when tested in the following function, the state property returns 1 -- connected) but get the following error at the point where the command is executed.
我能够连接到数据库(我的连接在代码的其他地方使用,并且在以下函数中进行测试时,状态属性返回1-已连接),但是在执行命令时出现以下错误。
Run-time error '-2147217887 (80040e21)':
运行时错误'-2147217887(80040e21)':
Multiple-stop OLE DB operation generated errors.多站OLE DB操作生成错误。 Check each OLD DB status value, if available.
检查每个OLD DB状态值(如果有)。 No work was done.
没有工作。
From what I've read online, it may be something to do with the parameter, but I can't see anything wrong with it (I've added a watch and inspected each item in the params collection in debug mode). 从我在网上阅读的内容来看,它可能与参数有关,但是我看不到任何问题(我添加了一块手表,并以调试模式检查了params集合中的每个项目)。
Here's the function that is intended to return the stored procedure results in an ADODB Recordset: 这是用于在ADODB记录集中返回存储过程结果的函数:
Public Function GetRecordset(CmdType As String, CmdText As String, Optional InputParams As Collection) As ADODB.Recordset
Dim prm As ADODB.Parameter
Select Case CmdType
Case "proc"
If cmd Is Nothing Then
Set cmd = New ADODB.Command
With cmd
Set .ActiveConnection = GetConnection
For Each prm In InputParams
.Parameters.Append prm
Next prm
Select Case CmdType
Case "proc": .CommandType = adCmdStoredProc
Case "sql": .CommandType = adCmdText
End Select
.CommandText = CmdText
Set rs = .Execute
End With
Set GetRecordset = rs
End If
Case "sql"
End Select
End Function
As above, the error occurs on the line: 如上所述,该错误发生在行上:
Set rs = .Execute
The expected input parameter in the stored procedure is of type numeric(6,0). 存储过程中预期的输入参数的类型为numeric(6,0)。 The parameter passed to the function is as follows:
传递给函数的参数如下:
prm.Direction = adParamInput
prm.Name = "@ISOWk"
prm.NumericScale = 6
prm.Precision = 0
prm.Type = adNumeric
prm.Value = 201613
I'm able to execute the stored procedure directly in SSMS so I am confident that it is not the issue here. 我能够直接在SSMS中执行存储过程,因此我确信这不是这里的问题。
Any suggestions welcome. 任何建议欢迎。
Thanks 谢谢
You have your .Precision
and .Scale
backwards: 您有
.Precision
和.Scale
向后.Scale
:
prm.NumericScale = 6
prm.Precision = 0
A value with a precision of 0 can store 0 digits. 精度为0的值可以存储0位数字。 If the data-type is
NUMERIC(6, 0)
the parameter should be: 如果数据类型为
NUMERIC(6, 0)
则参数应为:
prm.NumericScale = 0
prm.Precision = 6
Precision is the number on the left. 精度是左边的数字。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.