• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 305
  • Last Modified:

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?
0
longbloke69
Asked:
longbloke69
  • 4
  • 3
  • 2
1 Solution
 
Raja Jegan RSQL Server DBA & ArchitectCommented:
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.
0
 
longbloke69Author 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!
0
 
Raja Jegan RSQL Server DBA & ArchitectCommented:
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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Scott PletcherSenior DBACommented:
I don't know of any way to get that info in SQL Server.
0
 
longbloke69Author Commented:
Its just like in JavaScript, where you can check what the callee is named: Function.arguments.callee or window.callee.
0
 
Raja Jegan RSQL Server DBA & ArchitectCommented:
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.
0
 
longbloke69Author 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.
0
 
Scott PletcherSenior DBACommented:
>> 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.
0
 
longbloke69Author Commented:
Thank you
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now