SQL Server

CONTEXT_INFO()

Session context information enables applications to set binary values of up to 128 bytes that can be referenced in multiple batches, stored procedures, triggers, or user-defined functions operating on the same session. You can set a session context value by using the SET CONTEXT_INFO statement and retrieve it later by using CONTEXT_INFO() function as in the sample code below.

SELECT CONTEXT_INFO()

DECLARE @ci VARBINARY(128)

SET @ci = CAST('HELLO WORLD' AS VARBINARY)

SET CONTEXT_INFO @ci

-- read CONTEXT_INFO()
SELECT CAST(CONTEXT_INFO() AS VARCHAR(20))

-- read from DMV
SELECT session_id, CAST(context_info AS VARCHAR(20)) [context_info]
FROM sys.dm_exec_sessions 
WHERE session_id = @@SPID

More on MSDN

Leave a Reply

Your email address will not be published. Required fields are marked *