Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32)

后端 未结 8 604
粉色の甜心
粉色の甜心 2020-12-16 10:37

I am creating a store procedure but while executing the procedure i am getting the particular error.

Msg 217, Level 16, State 1, Procedure SendMail_Renewapp,

相关标签:
8条回答
  • 2020-12-16 10:59

    Remove the BEGIN and END for your IF statement

    example

    WHILE @@FETCH_STATUS = 0
    BEGIN
    
        IF @variable
        --NO BEGIN
           --Do this
        --NO END
    END
    
    0 讨论(0)
  • 2020-12-16 11:04

    Ok, So this one is pretty old, so I figured I would provide the correct answer. You should add SET NOCOUNT ON at the top of the stored procedure and SET NOCOUNT OFF before you attempt to return a result (your final select).

    Without this statement, your execution will treat every select statement as a result to output. When an external ADO or ADO.NET attempts to call the stored procedure and get a result, you will get the "Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32)" message. Its the select statement for your cursor that is blowing things up.

    reference: https://docs.microsoft.com/en-us/sql/t-sql/statements/set-nocount-transact-sql?view=sql-server-ver15

    0 讨论(0)
  • 2020-12-16 11:05

    ALTER your database for RECURSIVE_TRIGGERS.

    If nested triggers are allowed and a trigger in the chain starts an infinite loop, the nesting level is exceeded and the trigger terminates. That time you do get this error. so simply rune this query.

    USE yourdatabase 
     GO
        -- Turn recursive triggers OFF in the database. 
          ALTER DATABASE yourdatabase    
          SET RECURSIVE_TRIGGERS OFF 
    GO
    

    Hope your problem will resolve.

    0 讨论(0)
  • 2020-12-16 11:05

    Use

    RETURN
    

    at the end of the procedure

    0 讨论(0)
  • 2020-12-16 11:07

    Check trigger nesting level right at the beginning of the trigger by using TRIGGER_NESTLEVEL function and stop the trigger to perform action if the trigger level is greater than 1.

     IF TRIGGER_NESTLEVEL() > 1
         RETURN
    

    The error is occurring due to the nesting level exceeding its limit, because we all know that trigger continuously fires and its difficult to control that behavior of the trigger. The function TRIGGER_NESTLEVEL returns the nesting level and we can stop the nesting level to increase.

    0 讨论(0)
  • 2020-12-16 11:14

    The procedure is created with an EXEC of itself inside it. Therefore, a GO must be placed before the EXEC so the procedure will be Created/Altered before getting executed. Thus, avoiding the RECURSION.

    0 讨论(0)
提交回复
热议问题