title | description | author | ms.author | ms.date | ms.service | ms.subservice | ms.topic | f1_keywords | helpviewer_keywords | dev_langs | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
CONTEXT_INFO (Transact-SQL) |
CONTEXT_INFO (Transact-SQL) |
markingmyname |
maghan |
07/24/2017 |
sql |
t-sql |
reference |
|
|
|
[!INCLUDE SQL Server Azure SQL Database Azure SQL Managed Instance]
This function returns the context_info value either set for the current session or batch, or derived through use of the SET CONTEXT_INFO statement.
:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: Transact-SQL syntax conventions
CONTEXT_INFO()
The context_info value.
If context_info was not set:
- [!INCLUDEssNoVersion] returns NULL.
- [!INCLUDEssSDS] returns a unique session-specific GUID.
The Multiple Active Result Sets (MARS) feature enables applications to run multiple batches, or requests, at the same time, on the same connection. When one of the MARS connection batches runs SET CONTEXT_INFO, the CONTEXT_INFO
function returns the new context value, when the CONTEXT_INFO
function runs in the same batch as the SET statement. If the CONTEXT_INFO
function runs in one or more of the other connection batches, the CONTEXT_INFO
function does not return the new value unless those batches started after completion of the batch that ran the SET statement.
Requires no special permissions. The following system views store the context information, but querying these views directly requires SELECT and VIEW SERVER STATE permissions:
- sys.dm_exec_requests
- sys.dm_exec_sessions
- sys.sysprocesses
This 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
SET CONTEXT_INFO (Transact-SQL)
SESSION_CONTEXT (Transact-SQL)
sp_set_session_context (Transact-SQL)