debugsqlMinor
MS SQL Server 2014: which stored procedure is my error in?
Viewed 0 times
storederrorserversqlprocedurewhich2014
Problem
As a general question or three on Microsoft SQL Server 2014, that perhaps I should know the answer to already, or even perhaps did once -
When my stored procedures run other stored procedures, how can I find out which stored procedure's code generated the error?
Is there a particular way to handle errors from Transact-SQL that identifies the location of the error in a given stored procedure?
Can program code in a stored procedure obtain the name of the procedure it is in?
I am prepared to put "SET @MyNameIs = N'HastilyWrittenProcedure' " in program code if it's the only way. Then I can put "PRINT @MyNameIs + ' broke.' " in the error handler in everything.
When my stored procedures run other stored procedures, how can I find out which stored procedure's code generated the error?
Is there a particular way to handle errors from Transact-SQL that identifies the location of the error in a given stored procedure?
Can program code in a stored procedure obtain the name of the procedure it is in?
I am prepared to put "SET @MyNameIs = N'HastilyWrittenProcedure' " in program code if it's the only way. Then I can put "PRINT @MyNameIs + ' broke.' " in the error handler in everything.
Solution
Use @@procid to get the currently executing routine and object_name() to convert the id to a name
Hth
Hth
Context
StackExchange Database Administrators Q#289696, answer score: 5
Revisions (0)
No revisions yet.