我正在尝试更新一些旧功能。有一个具有一个输入参数和两个输出参数的存储过程。尝试执行代码时出现以下错误:
Microsoft OLE DB提供程序的ODBC驱动程序错误'80040e21' 多步OLE DB操作生成错误。检查每个OLE DB状态值(如果有)。没有工作。 /student.asp,第30行
存储过程:
ALTER PROCEDURE [Api].[GetKeyByAuthId]
@AuthenticationId uniqueidentifier
, @Key int = NULL OUTPUT
, @type varchar(25) = NULL OUTPUT
直接通话效果很好:
USE [Development]
GO
DECLARE @return_value int,
@Key int,
@type varchar(25)
EXEC @return_value = [Api].[GetKeyByAuthId]
@AuthenticationId = '0550F579-DBDA-4C41-82B3-453841A6232E',
@Key = @Key OUTPUT,
@type = @type OUTPUT
SELECT @Key as N'@Key',
@type as N'@type'
SELECT 'Return Value' = @return_value
GO
身份验证ID是唯一的标识符,并通过页面上的查询字符串接收。这是我的代码,第30行是cmd.Execute:
var cmd = Server.CreateObject("ADODB.Command");
cmd.CommandText = "Api.GetKeyByAuthId";
cmd.CommandType = 4; // Stored procedure
var p = cmd.Parameters;
p.Append(cmd.CreateParameter("@AuthenticationId", 72, 1));
p.Append(cmd.CreateParameter("@Key", 3, 2, 9));
p.Append(cmd.CreateParameter("@type", 200, 2, 25));
cmd("@AuthenticationId") = aid;
cmd.ActiveConnection = Conn;
cmd.Execute();
Key = cmd.Parameters("@Key");
type = cmd.Parameters("@type");
在评论中讨论了数据类型之后
您提到存储过程期望@Key
为,Int
但该字段的基础表数据类型为BigInt
。
警告
这种方法的问题在于,从
BigInt
到的转换Int
非常危险(请参阅SQL-安全地将BIGINT向下转换为INT)。大多数时候你会得到Msg 8115, Level 16, State 2, Line 5 Arithmetic overflow error converting expression to data type int.
您可以使用以下组合来抑制异常
SET ANSI_WARNINGS OFF -- Divide-by-zero and arithmetic overflow errors cause null values to be returned SET ARITHABORT OFF -- Don't terminate the query on Divide-by-zero and arithmetic overflow errors SET ARITHIGNORE ON -- Suppress errors from Divide-by-zero and arithmetic overflow errors
我的猜测是
多步OLE DB操作生成错误
存储过程中的错误是由引起的,Arithetic overflow error
因为您要检索的值@Key
太大而无法容纳Int
数据类型。
如果可能,我将与您的开发人员联系并解释情况,然后查看是否可以将存储过程修改为@Key
as BigInt
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句