Getting the CONTEXT_INFO()

  • Comments posted to this topic are about the item Getting the CONTEXT_INFO()

  • Good question, thanks Steve.

    ...

  • Nice question, thanks Steve

    ____________________________________________
    Space, the final frontier? not any more...
    All limits henceforth are self-imposed.
    “libera tute vulgaris ex”

  • set CONTEXT_INFO 55
    SELECT cast(substring(CONTEXT_INFO(),1,4) as int)

  • The pedant in me would like to point out that you are getting 55 back, just not in a base 10 integer format.

    If you're not getting back the same value when you context_info(), keep in mind these things about the stored value:
    1. It's global to the session id, so it's possible to fall out of scope, maybe your application has closed the SQL connection and re-opened it in which case the previous value is lost forever
    2. There is only a single structure so it's possible to overwrite, maybe your application has subsequently updated the value in which case the previous value is gone forever

  • lmalatesta - Tuesday, February 27, 2018 8:26 AM

    The pedant in me would like to point out that you are getting 55 back, just not in a base 10 integer format.

    Hi there. Actually, in this case you aren't exactly getting 55 back. I mean, the value is in there somewhere, just not where it needs to be for doing a simple convert back to INT. It's an "issue" with how the CONTEXT_INFO() built-in function returns the context_info value. I just wrote a post explaining this behavior:

    Why Doesn’t CONTEXT_INFO() Return the Exact Value Set by SET CONTEXT_INFO?
    Take care,
    Solomon...

    SQL#https://SQLsharp.com/ ( SQLCLR library ofover 340 Functions and Procedures)
    Sql Quantum Lifthttps://SqlQuantumLift.com/ ( company )
    Sql Quantum Leaphttps://SqlQuantumLeap.com/ ( blog )
    Info sitesCollations     •     Module Signing     •     SQLCLR

  • Solomon Rutzky - Tuesday, April 10, 2018 11:10 AM

    lmalatesta - Tuesday, February 27, 2018 8:26 AM

    The pedant in me would like to point out that you are getting 55 back, just not in a base 10 integer format.

    Hi there. Actually, in this case you aren't exactly getting 55 back. I mean, the value is in there somewhere, just not where it needs to be for doing a simple convert back to INT. It's an "issue" with how the CONTEXT_INFO() built-in function returns the context_info value. I just wrote a post explaining this behavior:

    The pedant in me would like to point out that "getting 55 back" and "getting 55 back in a way that is simple to convert back to INT" are two different things. Getting 55 back as a varbinary value padded by 0s that requires some fiddling is still getting 55 back.

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply