Link to home
Start Free TrialLog in
Avatar of longbloke69
longbloke69

asked on

Dynamically getting the callee name of a stored procedure

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?
Avatar of Raja Jegan R
Raja Jegan R
Flag of India image

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.
Avatar of longbloke69
longbloke69

ASKER

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!
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
I don't know of any way to get that info in SQL Server.
Its just like in JavaScript, where you can check what the callee is named: Function.arguments.callee or window.callee.
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.
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.
ASKER CERTIFIED SOLUTION
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you