Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Maximum stored procedure nesting Expand / Collapse
Author
Message
Posted Thursday, November 21, 2013 1:01 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Monday, October 27, 2014 8:34 PM
Points: 68, Visits: 211
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
Post #1516566
Posted Thursday, November 21, 2013 1:14 PM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Yesterday @ 6:05 AM
Points: 40,258, Visits: 36,681
Without seeing the procedure, no.


Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
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

Post #1516569
Posted Thursday, November 21, 2013 1:23 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Monday, October 27, 2014 8:34 PM
Points: 68, Visits: 211
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
Post #1516573
Posted Thursday, November 21, 2013 1:26 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 2:26 PM
Points: 13,093, Visits: 12,573
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 Moden's 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)
Post #1516575
Posted Thursday, November 21, 2013 1:38 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Monday, October 27, 2014 8:34 PM
Points: 68, Visits: 211
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.
Post #1516578
Posted Thursday, November 21, 2013 2:12 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 2:26 PM
Points: 13,093, Visits: 12,573
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 Moden's 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)
Post #1516582
Posted Thursday, November 21, 2013 2:41 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Yesterday @ 9:43 AM
Points: 256, Visits: 1,531
This is the error I get.

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


Post #1516592
Posted Thursday, November 21, 2013 3:03 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 2:26 PM
Points: 13,093, Visits: 12,573
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.


_______________________________________________________________

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 Moden's 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)
Post #1516597
Posted Thursday, November 21, 2013 3:12 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Yesterday @ 9:43 AM
Points: 256, Visits: 1,531
Post #1516602
Posted Thursday, November 21, 2013 3:31 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Monday, October 27, 2014 8:34 PM
Points: 68, Visits: 211
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.
Post #1516605
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse