Tuesday, February 8, 2011

CONTEXT_INFO : SQL Server

CONTEXT_INFO() function returns the contenxt_info value that was set for the current session or batch by using the SET CONTEXT_INFO statement. It can associate up to 128 bytes of binary information with the current session or connection.

You can set the context_info using:
SET CONTEXT_INFO { binary_str | @binary_var }
where binary_str is a binary constant / @binary_var is varbinary or binary variable.

In SQL server, session context information is also stored in the context_info columns of the following system views:
  • sys.dm_exec_requests
  • sys.dm_exec_sessions
  • sys.sysprocesses

The preferred way to retrieve the context information for the current session is to use the CONTEXT_INFO() function.

Example:
SET CONTEXT_INFO 0x1111122222
GO
SELECT CONTEXT_INFO()
GO

Usage:
  • Passing information from a stored procedure that performs DML operations to the triggers Read more
  • To make SQL table will never be modified except via a stored procedure Read more

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.