Reputation: 70307
Is there way to tell what proc called the currently executing stored procedure.
Upvotes: 1
Views: 153
Reputation: 139
This question was in the result list when I was researching the same issue, however I found the following code
print object_name(@@PROCID)
which works a treat within a stored proc, to return the name of the stored proc which contained it. The original article I found at sql server central.
Upvotes: 0
Reputation: 58261
There is currently no way to do this.
But please... Go here and let them know that you want that feature.
EDIT:
I looked into this a little more, and found a potential workaround (ugly to use for this purpose, but it looks like it might be doable):
This is from Books Online:
So here's my idea:
add this code to all of your procedures:
DECLARE @UID VARBINARY(128)
SELECT @UID = CAST('ThisProcedureName' AS VARBINARY(128))
SET CONTEXT_INFO @UID
Then you add this check where you need it:
DECLARE @Message varbinary(128)
SELECT @Message = cast('TestB' as varbinary(128))
IF (@Message = CONTEXT_INFO()) BEGIN
RAISERROR('Not Allowed unless from procedure XX', 16, 1)
END
Upvotes: 1