Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

CONTEXT_INFO (Transact-SQL)

 

Applies To: SQL Server 2014, SQL Server 2016 Preview

Returns the context_info value that was set for the current session or batch by using the SET CONTEXT_INFO statement.

Applies to: SQL Server (SQL Server 2008 through current version), Azure SQL Database.

Topic link icon Transact-SQL Syntax Conventions


CONTEXT_INFO()

The value of context_info.

If context_info was not set:

  • In SQL Server returns NULL.

  • In SQL Database returns a unique session-specific GUID.

Multiple active result sets (MARS) enables applications to run multiple batches, or requests, at the same time on the same connection. When one of the batches on a MARS connection runs SET CONTEXT_INFO, the new context value is returned by the CONTEXT_INFO function when it is run in the same batch as the SET statement. The new value is not returned by the CONTEXT_INFO function run in one or more of the other batches on the connection, unless they started after the batch that ran the SET statement completed.

Requires no special permissions. The context information is also stored in the sys.dm_exec_requests, sys.dm_exec_sessions, and sys.sysprocesses system views, but querying the views directly requires SELECT and VIEW SERVER STATE permissions.

The following simple example sets the context_info value to 0x1256698456, and then uses the CONTEXT_INFO function to retrieve the value.

SET CONTEXT_INFO 0x1256698456;
GO
SELECT CONTEXT_INFO();
GO

Community Additions

ADD
Show:
© 2015 Microsoft