SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Maximum stored procedure nesting


Maximum stored procedure nesting

Author
Message
N_Muller
N_Muller
SSC-Addicted
SSC-Addicted (468 reputation)SSC-Addicted (468 reputation)SSC-Addicted (468 reputation)SSC-Addicted (468 reputation)SSC-Addicted (468 reputation)SSC-Addicted (468 reputation)SSC-Addicted (468 reputation)SSC-Addicted (468 reputation)

Group: General Forum Members
Points: 468 Visits: 443
I have a stored procedure that is giving me the error:

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

The procedure is not recursive but it contains a recursive CTE. The error is coming from a call to that adds an error notification inside a "begin catch"/"end catch". The CTE is between "begin try"/"end try".

Can anyone help with this? Thanks
GilaMonster
GilaMonster
SSC Guru
SSC Guru (114K reputation)SSC Guru (114K reputation)SSC Guru (114K reputation)SSC Guru (114K reputation)SSC Guru (114K reputation)SSC Guru (114K reputation)SSC Guru (114K reputation)SSC Guru (114K reputation)

Group: General Forum Members
Points: 114373 Visits: 45494
Without seeing the procedure, no.

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


N_Muller
N_Muller
SSC-Addicted
SSC-Addicted (468 reputation)SSC-Addicted (468 reputation)SSC-Addicted (468 reputation)SSC-Addicted (468 reputation)SSC-Addicted (468 reputation)SSC-Addicted (468 reputation)SSC-Addicted (468 reputation)SSC-Addicted (468 reputation)

Group: General Forum Members
Points: 468 Visits: 443
Here's a snippet of the procedure. The error is pointing to MyNotificationProcedure.

create procedure MyProc
as

begin try

-- SQL Code

;with MyRecursion
as
(
-- Anchor
union all
-- Recursion
)
select * from MyRecursion

-- SQL Code

return 0
end try
begin catch
exec MyNotificationProcedure @msg = 'Error in MyRecursion'

return -1
end catch

go
Sean Lange
Sean Lange
SSC-Dedicated
SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)

Group: General Forum Members
Points: 33148 Visits: 17669
nelson.muller (11/21/2013)
Here's a snippet of the procedure. The error is pointing to MyNotificationProcedure.

create procedure MyProc
as

begin try

-- SQL Code

;with MyRecursion
as
(
-- Anchor
union all
-- Recursion
)
select * from MyRecursion

-- SQL Code

return 0
end try
begin catch
exec MyNotificationProcedure @msg = 'Error in MyRecursion'

return -1
end catch

go


This doesn't help. Remember we can't see your screen, we have no idea what your tables look like and we don't know what you are trying to do.

About all I can tell you is that you have recursion going at least to 33 levels which raises the exception that you are seeing.

Please take a few minutes and read the first article in my signature about best practices when posting questions.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
N_Muller
N_Muller
SSC-Addicted
SSC-Addicted (468 reputation)SSC-Addicted (468 reputation)SSC-Addicted (468 reputation)SSC-Addicted (468 reputation)SSC-Addicted (468 reputation)SSC-Addicted (468 reputation)SSC-Addicted (468 reputation)SSC-Addicted (468 reputation)

Group: General Forum Members
Points: 468 Visits: 443
I understand the best practices and I am quite experienced with SQL server. I haven't seen this error before. Unfortunately the procedure is over 2,000 lines long and has a very complex process in a complex data model. Let me try to rephrase my question. The error is:

Msg 217, Level 16, State 1, Procedure MyNotification, Line 75
Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32).

The call to MyNotification is done within a begin/end catch. Does that mean there is a nesting inside MyNotification, or is the error because there is a recursive CTE between the begin/end try? Thanks again.
Sean Lange
Sean Lange
SSC-Dedicated
SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)

Group: General Forum Members
Points: 33148 Visits: 17669
nelson.muller (11/21/2013)
I understand the best practices and I am quite experienced with SQL server. I haven't seen this error before. Unfortunately the procedure is over 2,000 lines long and has a very complex process in a complex data model. Let me try to rephrase my question. The error is:

Msg 217, Level 16, State 1, Procedure MyNotification, Line 75
Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32).

The call to MyNotification is done within a begin/end catch. Does that mean there is a nesting inside MyNotification, or is the error because there is a recursive CTE between the begin/end try? Thanks again.


There is nesting of some kind or other going on somewhere in your code right around line 75.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
benjamin.reyes
benjamin.reyes
Say Hey Kid
Say Hey Kid (693 reputation)Say Hey Kid (693 reputation)Say Hey Kid (693 reputation)Say Hey Kid (693 reputation)Say Hey Kid (693 reputation)Say Hey Kid (693 reputation)Say Hey Kid (693 reputation)Say Hey Kid (693 reputation)

Group: General Forum Members
Points: 693 Visits: 2286
This is the error I get.

Msg 156, Level 15, State 1, Procedure MyProc, Line 13
Incorrect syntax near the keyword 'union'.
Sean Lange
Sean Lange
SSC-Dedicated
SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)

Group: General Forum Members
Points: 33148 Visits: 17669
benjamin.reyes (11/21/2013)
This is the error I get.

Msg 156, Level 15, State 1, Procedure MyProc, Line 13
Incorrect syntax near the keyword 'union'.




The OP obviously posted pseudocode. There is nothing like syntax in there that would actually work. :-P

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
benjamin.reyes
benjamin.reyes
Say Hey Kid
Say Hey Kid (693 reputation)Say Hey Kid (693 reputation)Say Hey Kid (693 reputation)Say Hey Kid (693 reputation)Say Hey Kid (693 reputation)Say Hey Kid (693 reputation)Say Hey Kid (693 reputation)Say Hey Kid (693 reputation)

Group: General Forum Members
Points: 693 Visits: 2286
;-)
N_Muller
N_Muller
SSC-Addicted
SSC-Addicted (468 reputation)SSC-Addicted (468 reputation)SSC-Addicted (468 reputation)SSC-Addicted (468 reputation)SSC-Addicted (468 reputation)SSC-Addicted (468 reputation)SSC-Addicted (468 reputation)SSC-Addicted (468 reputation)

Group: General Forum Members
Points: 468 Visits: 443
Thanks everyone. I did find what the issue was, and that's because I was running the procedure after a SET FMTLONLY ON, which forced every if statement to run. Although at run time the procedure is protected against recursion, the FMTONLY caused SQL Server to "think" it had recursion.

Thanks everyone for the responses.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search