sql-serversql-server-2008-r2context-info

How to increase the 128byte limit of CONTEXT_INFO in SQLServer 2008 R2?


It's like a context space for ants!


Solution

  • There is no way to increase the size of the CONTEXT_INFO. It is 128 bytes, and we cannot change it.

    If you need more space, you could implement your own session context information. You could create a permanent ContextInfo or global ##ContextInfo or tempdb..ContextInfo table that holds all the data you neeed to track per session. Set the table's primary key to something unique like an IDENTITY. You could also use the @@SPID of the current connection.

    When a request is started, INSERT a record into this ContextInfo table (or lookup the existing record on the @@SPID), and SET CONTEXT_INFO to the associated key (or just use the @@SPID). After your connection is finished, clean up the ContextInfo table and clear the CONTEXT_INFO information.