06-15-2016 01:55 PM
Aha! Thank you sir. That might indeed be the problem I'm having.
SQL server is showing me the information as a hex code of 2048 characters (hence one reason I didn't display the entire data string). I originally copied the data to my test "Convert this to usable data" code and it pasted as the hex (expected I suppose). I'll try forcing it to a byte array and working with that. I'll have to rewrite my code (because it was converting the string to a byte array and then to what I needed anyway).
Note: Yes, doing the testing by pasting the string was intelligent at the time as I didn't have SQL on my computer when I was originally writing the conversion tool.
Anyways, thank you again. Stupid little misunderstanding on my part, and I appreciate the help immensely.
06-15-2016 01:57 PM
06-15-2016 02:11 PM
That's the thing. Even with it in hex display, it was wrong.
I think the other suggestion will work, I just have to switch my code around and not use the fetch/query database functions as those don't like converting straight to byte array for some reason.
06-15-2016 02:16 PM
Actually, what I suggested will work...it just needed an additional parameter. Use this in your select statement.
CONVERT(varchar(max), db_binary_field_name, 1)
06-15-2016 02:49 PM
I'll give that a try as well at some point. I'm sure I'll have to trim down my code a bit later, so that may be useful. Taking my data as a byte array definitely works (just tested it).
06-15-2016 03:00 PM
OK but it doesn't require any post processing on the data. With a 1 as the last parameter, the value returned is the hex data (as a string) with the '0x' prefix. With a 2 as the last parameter, the '0x' is removed.
I am using MSSQL. I'm not sure if other versions of SQL support this function or not. When working with databases, I'm always looking for ways to offload some of the work to the server so that I get the data back exactly how I want it.