简体   繁体   English

使用ADO命令在SQL Server中运行存储过程时如何解决“多站OLE DB操作…”错误

[英]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.

相关问题 SSIS Access DB - 多步 OLE DB 操作在执行 SQL 过程时产生错误 - SSIS Access DB - Multiple-step OLE DB operation generated errors while executing SQL Procedure 如何修复 SSIS 中的多步 OLE DB 操作错误? - How do I fix the multiple-step OLE DB operation errors in SSIS? 请求的操作需要OLE DB会话对象... - 通过ADO将Excel连接到SQL服务器 - Requested operation requires an OLE DB Session object… - Connecting Excel to SQL server via ADO SQL Server存储过程会引发多个错误 - SQL Server stored procedure throws multiple errors 最佳实践:在OLE DB源中发送“来自变量的SQL命令”的存储过程? - Best practice: sending a stored procedure for “SQL Command from Variable” in OLE DB Source? 如何修复SQL Server数据工具中的OLE DB错误 - How to fix an OLE DB error in SQL Server Data Tools 如何停止使用SQL Server执行存储过程? - How to stop the execution of a Stored Procedure using SQL Server? 如何在不使用 sql 服务器代理的情况下安排我的存储过程在 SQL 中的数据更新时运行? - How to schedule my stored procedure to run when there is an update in data in SQL without using the sql server agent? SSIS OLE DB SQL 命令 - 从嵌套存储过程中获取返回值 - SSIS OLE DB SQL COMMAND - Getting return value from nested stored procedure Microsoft OLE DB提供程序的SQL Server错误'80040e14'找不到存储的过程 - Microsoft OLE DB Provider for SQL Server error '80040e14' Could not find stored procedure
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM