The topic describes the DF017 T-SQL code analysis rule.
BEST PRACTICE
CONTEXT_INFO is used.
It is not recommended to use CONTEXT_INFO because binary data may be corrupted. Use SESSION_CONTEXT instead.
The behavior of SESSION_CONTEXT with MARS (Multiple Active Result Sets) is similar to that of CONTEXT_INFO. If a MARS batch updates a key-value pair, the new value isn’t available in other MARS batches on the same connection until they start after the updating batch is completed. When multiple MARS batches run on a connection, values cannot be set as “read_only” to avoid race conditions and uncertainty about which value takes precedence.
DECLARE @user_id VARBINARY(128);
SET @user_id = cast(4 AS VARBINARY(128));
SET context_info @user_id;
SELECT CONTEXT_INFO() AS user_id;
EXEC sp_set_session_context 'user_id', 4;
SELECT session_context(N'user_id');