How do you access the Context_Info() variable in SQL2005 Profiler?

前端 未结 1 801
死守一世寂寞
死守一世寂寞 2021-01-23 07:19

I am using the Context_Info() variable to keep track of the user that is executing a stored procedure and free-form sql. When troubleshooting issues on this server everyone sess

1条回答
  •  梦毁少年i
    2021-01-23 08:15

    You can use the UserConfigurable Events along with sp_trace_generateevent (EventId's 82-91) when setting the context_info() to output the values to the trace. Your option is to either do that, or trace the statements setting the context_info(). You won't be able to get the value any other way unless you write a process to dump the output of sys.dm_exec_sessions in a loop while the trace is running:

    select session_id, cast(context_info as varchar(128)) as context_info
    from sys.dm_exec_sessions
    where session_id > 50 -- user sessions
    

    for SQL 2000 you can use sysprocesses:

    select spid, cast(context_info as varchar(128)) as context_info
    from sysprocesses
    where sid > 50 -- user sessions
    

    0 讨论(0)
提交回复
热议问题