MS SQL Server - List All Session Context Values

Viewed 1082

I have recently started using SQL Server 2016 and I'm using SESSION_CONTEXT values to pass some data around.

I'm trying to find out if there is any way to read all session context settings in one. To clarify this is for debugging purposes only - I can already access individual settings, (see code below). I would like to be able to read all such settings in one go if possible.

-- What I Have
EXEC sp_set_session_context 'SortOrder','Price ASC'
EXEC sp_set_session_context 'ItemsPerPage',20

SELECT SESSION_CONTEXT(N'SortOrder') [SortOrder]
SELECT SESSION_CONTEXT(N'ItemsPerPage') [ItemsPerPage]
SELECT SESSION_CONTEXT(N'NotSetYet') [NotSetYet]

-- What I'd like
SELECT * FROM SESSION_CONTEXT_TABLE

Any help gratefully received.

Many Thanks.

1 Answers

Session Context Stored in System pages so you can not retrieve the list of all context without having the key.

If you are looking for global parameters try to save as JSON, XML or CSV string and retrieve with the key.

Related