简体   繁体   English

通过更新SQL存储过程错误

[英]SQL Stored Procedure error by updating

Im trying to use a stored procedure with parameter, in this case the OrderID. 我试图使用带有参数的存储过程,在这种情况下为OrderID。 But i'm getting the error : 'Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32).' 但是我遇到了错误: “超出了最大存储过程,函数,触发器或视图嵌套级别(限制32)。”

My C# methode: 我的C#方法:

using (SqlCommand cmd = new SqlCommand("UpdateStock", con))
        {
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@OrderID", SqlDbType.Int).Value = OrderId;
            cmd.ExecuteNonQuery();
        }

My Stored Procedure: 我的存储过程:

CREATE PROCEDURE [dbo].[UpdateStock] @OrderID int
AS
BEGIN
    UPDATE Products SET Stock = Stock -1 FROM Products INNER JOIN 
OrderDetails ON 
Products.ProductId = OrderDetails.ProductID WHERE OrderDetails.OrderID = 
@OrderID
END
GO

Maybe you guys can help me out? 也许你们可以帮帮我吗?

Looking at the code you provided so far looks fine. 查看到目前为止提供的代码看起来不错。 However the error is saying something like - somewhere, a stored procedure is calling another stored procedure and then again and again.. too many times. 但是错误表明类似-在某个地方,存储过程正在调用另一个存储过程,然后又一次又一次..太多次了。 It could also mean that there is 1 stored procedure calling itself too many times. 这也可能意味着有1个存储过程调用了太多次。

So the provided code doesn't show this behavior so I would suggest looking elsewhere. 因此提供的代码没有显示此行为,所以我建议您在别处查找。 As mentioned in the comments a good place to look are the triggers on the Products table. 正如评论中提到的,“产品”表上的触发器是一个不错的地方。 A trigger might run when you try to update it which could be the root of the problem. 当您尝试更新触发器时,触发器可能会运行,这可能是问题的根源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM