1

I have a procedure that is doing INSERT/DELETE operations over table and a trigger which is logging the changes in second table.

What I need is to pass the security user id that instantiated the procedure call to the trigger in order to record who user has made the changes.

It seems that the only way to do this is to use SET CONTEXT_INFO and CONTEXT_INFO().

The issue is, I am not able to extract the number(the user id). For example, the code below:

SET CONTEXT_INFO 10001
GO
SELECT CAST(CONTEXT_INFO() AS INT)

returns 0.

4

1 回答 1

1

上下文信息是binary/varbinary,因此您可以尝试binary先转换为,int然后再转换为:

SELECT CAST(CAST(CONTEXT_INFO() AS BINARY(4)) as INT)
于 2013-09-19T11:12:04.397 回答