We help IT Professionals succeed at work.

Dynamically getting the callee name of a stored procedure

Medium Priority
329 Views
Last Modified: 2012-05-06
I am calling a Error Handling/reporting stored procedure from within another stored proc.

I would like the error handling/reporting stored procedure to record which stored procedure it was called from, is this possible?
Comment
Watch Question

Raja Jegan RSQL Server DBA & Architect, EE Solution Guide
CERTIFIED EXPERT
Awarded 2009
Distinguished Expert 2019

Commented:
You can pass that the calling procedure name as a parameter to this procedure so that if any error happens, you can track which procedure called it.

Ideal way is to have a log table and insert records into it each and every time, a procedure is called out.

Author

Commented:
Yea thats what I am doing now, but, I would like to get the name automatically, so i can just run the stored procedure in every procedure i see fit, without needing to update that parameter. Just a streamlined way of doing it!
Raja Jegan RSQL Server DBA & Architect, EE Solution Guide
CERTIFIED EXPERT
Awarded 2009
Distinguished Expert 2019

Commented:
I didn't find any option for that since a procedure can be called anywhere either from the application or from query analyzer like that.  Anyhow will check it revert if I find some possible solutions
Scott PletcherSenior DBA
CERTIFIED EXPERT
Most Valuable Expert 2018
Distinguished Expert 2019

Commented:
I don't know of any way to get that info in SQL Server.

Author

Commented:
Its just like in JavaScript, where you can check what the callee is named: Function.arguments.callee or window.callee.
Raja Jegan RSQL Server DBA & Architect, EE Solution Guide
CERTIFIED EXPERT
Awarded 2009
Distinguished Expert 2019

Commented:
Thats practically impossible.
Assume an user is executing procedure from Enterprise Manager.
Another from SSMS.
Another from Toad.
Another from a master procedure.
Another from a nested level 2 procedure.
Etc.,

Hence its practically not possible to identify the user without using a Parameter for that query
And hence the answer for your question is No.

Author

Commented:
The Procedure I am calling will only ever be called from another stored procedure, and it's that stored procedure that I would like to identify, not the user.
Senior DBA
CERTIFIED EXPERT
Most Valuable Expert 2018
Distinguished Expert 2019
Commented:
>> Its just like in JavaScript, where you can check what the callee is named: Function.arguments.callee or window.callee. <<

Unfortunately SQL doesn't expose its call stack to you, afaik.  So, yes, *SQL* knows who called it (most likely), but he doesn't give you an interface to get that info.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Thank you
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.