In SQL Server, a varbinary(max) looks like '0xFE12CE34AB27' when looking at query results in a grid result within Management Studio. How can I copy a value looking like that and convert it back into a byte array via C#?
Asked
Active
Viewed 645 times
0
-
2So just to clarify, you're *copying the string value* (e.g. via the clipboard) - this isn't about fetching from the database in C#? – Jon Skeet Oct 10 '12 at 19:17
-
1http://stackoverflow.com/questions/3916049/convert-sql-binary-to-byte-array – mgidell Oct 10 '12 at 19:17
-
If you retrieve the value from the database using C# it wont be in a string representation. Also Management Studio might not be showing the complete binary file but rather the first part of it. – Magnus Oct 10 '12 at 19:18
-
Jon, you're correct, I'm just trying to copy and paste the value into LinqPad to decode it as I'm just trying to troubleshoot something quickly. – James Alexander Oct 10 '12 at 19:23
1 Answers
1
The '0xFE12CE34AB27'
string you see is an artifact of the Mgmt Studio.
Your data already is a byte array, don't do anything.

H H
- 263,252
- 30
- 330
- 514
-
-
Then say 'via Clipboard', not 'via C#'. Seems like you're using the wrong tool(s) here. – H H Oct 10 '12 at 19:31
-
@JamesAlexander You are not guaranteed to get the complete binary file if you do it like that. Mgmt Studio cuts the data. – Magnus Oct 10 '12 at 19:43