SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Context_info() data


Context_info() data

Author
Message
Steve Jones
Steve Jones
SSC Guru
SSC Guru (349K reputation)SSC Guru (349K reputation)SSC Guru (349K reputation)SSC Guru (349K reputation)SSC Guru (349K reputation)SSC Guru (349K reputation)SSC Guru (349K reputation)SSC Guru (349K reputation)

Group: Administrators
Points: 349800 Visits: 20195
Comments posted to this topic are about the item Context_info() data

Follow me on Twitter: @way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
Stewart "Arturius" Campbell
Stewart "Arturius" Campbell
SSC-Dedicated
SSC-Dedicated (37K reputation)SSC-Dedicated (37K reputation)SSC-Dedicated (37K reputation)SSC-Dedicated (37K reputation)SSC-Dedicated (37K reputation)SSC-Dedicated (37K reputation)SSC-Dedicated (37K reputation)SSC-Dedicated (37K reputation)

Group: General Forum Members
Points: 37508 Visits: 7738
Interesting question, thanks Steve
Never used this before, so definitely learned something new

____________________________________________
Space, the final frontier? not any more...
All limits henceforth are self-imposed.
“libera tute vulgaris ex”
edwardwill
edwardwill
SSCrazy
SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)

Group: General Forum Members
Points: 2461 Visits: 421
The MSDN article to which you link and which you cite in support of your (incorrect) answer states "Associates up to 128 bytes of binary information with the current session or connection." So the correct answer is a.
PaulyDee
PaulyDee
Valued Member
Valued Member (53 reputation)Valued Member (53 reputation)Valued Member (53 reputation)Valued Member (53 reputation)Valued Member (53 reputation)Valued Member (53 reputation)Valued Member (53 reputation)Valued Member (53 reputation)

Group: General Forum Members
Points: 53 Visits: 17
You can only pass in a binary variable. The fact you're converting other datatypes to binary is irrelevant ;-)
Agree with the above that the answer should be a).
paul s-306273
paul s-306273
SSCertifiable
SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)

Group: General Forum Members
Points: 5787 Visits: 1295
Binary? 57% think so at the moment.
Toreador
Toreador
SSCertifiable
SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)

Group: General Forum Members
Points: 6187 Visits: 8303
Yup, should definitely be Binary Data, the fact that some other data types get implicitly converted is irrelevant.
Bobby Russell
Bobby Russell
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1767 Visits: 549
Answer A is the correct answer. Conversion of data to a type means it became that type.
Solomon Rutzky
Solomon Rutzky
SSCertifiable
SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)

Group: General Forum Members
Points: 7526 Visits: 3139
As others have mentioned, the correct answer is actually (a) for "binary data" only. Implicit conversions, while they work most of the time, shouldn't be relied upon, and in this case, it isn't doing what you think it is. You can specify an INT value when executing SET CONTEXT_INFO, but that isn't exactly what is getting "passed in", as the following test demonstrates.

Executing the following:

SET CONTEXT_INFO 12;

DECLARE @ImplicitConvert VARBINARY(128) = 12;

SELECT CONTEXT_INFO() AS [FullValue],
CONVERT(INT, CONTEXT_INFO()) AS [BackToInt],
CONVERT(INT, CONVERT(BINARY(4), CONTEXT_INFO())) AS [BackToIntViaBinary(4)],
CONVERT(VARBINARY(128), 12) AS [ExplicitConvert],
@ImplicitConvert AS [ImplicitConvert];


Returns:

FullValue                 BackToInt   BackToIntViaBinary(4)   ExplicitConvert   ImplicitConvert
0x0000000C00000....0000 0 12 0x0000000C 0x0000000C




I partially truncated the "FullValue" value as we don't need to see the remaining (out of 128) bytes worth of 0's. But as you can see, an INT was passed in, but you cannot get the INT back out unless you truncate the value down to the 4 bytes of an INT. While the "12" is correctly (implicitly) converted to 0x0C, it seems a bit misleading to say that this "works". But along those lines, even just saying "binary" data isn't enough since explicitly converting to VARBINARY(128) has the same effect as when passing in just "12".

The only reliable datatype to set CONTEXT_INFO to, where you get out exactly what you put in, is BINARY(128), as you can see below:

DECLARE @Bin128 BINARY(128) = 23;
SET CONTEXT_INFO @Bin128;

SELECT CONVERT(INT, CONTEXT_INFO()) AS [BackToInt];
-- 23


Take care,
Solomon..


SQL# - https://SQLsharp.com/
Sql Quantum Lift - https://SqlQuantumLift.com/
edwardwill
edwardwill
SSCrazy
SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)

Group: General Forum Members
Points: 2461 Visits: 421
Can I have my point(s) now please?
Tom Uellner
Tom Uellner
SSC Eights!
SSC Eights! (891 reputation)SSC Eights! (891 reputation)SSC Eights! (891 reputation)SSC Eights! (891 reputation)SSC Eights! (891 reputation)SSC Eights! (891 reputation)SSC Eights! (891 reputation)SSC Eights! (891 reputation)

Group: General Forum Members
Points: 891 Visits: 1629
According to the Microsoft docs you can pass binary or a constant that is implicitly convertible to binary making Steve's answer correct ( but not popular Smile )

binary_str
Is a binary constant, or a constant that is implicitly convertible to binary, to associate with the current session or connection.+

@ binary_var
Is a varbinary or binary variable holding a context value to associate with the current session or connection.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search