views:

186

answers:

1

We currently use the SQL Publishing Wizard to back up our database schemas and data, however we have some database tables with hashed passwords that contain the null character (chr(0)). When SQL Publishing Wizard generates the insert data scripts, the null character causes errors when we try and run the resulting SQL - it appears to ignore ALL TEXT after the first instance of this character in a script. We recently tried out RedGate SQL Compare, and found that it has the same issue with this character. I have confirmed it is ascii character code 0 by running the ascii() sql function against the offending record.

A sample of the error we are getting is:

Unclosed quotation mark after the character string '??`????{??0???

The fun part is, I can't really paste a sample Insert statement because of course everything that appears after the CHR(0) is being omitted when pasting!

+1  A: 

Change the definition of the column to VARBINARY. The data you store in there doesn't seem to be an appropiate VARCHAR to start with.

This will ripple through the code that uses the column as you'll get a byte[] CLR tpe back in the client, and you should change your insert/update code accordingly. But after all, a passowrd hash is a byte[], not a string.

Remus Rusanu
This sounds like a viable solution - I will look into it and let you know how it goes.
Keith
I just tried this, however since we're tied to the third party algorithm, the system is obviously spitting out "can't convert byte[] to string" errors. And of course, this is in a proprietary DLL that we don't have access to modify the source. Do you have any suggestions for workarounds that don't involve modifying the core data types?
Keith
You can always convert the byte[] to and from string, using Encoding.GetString() and Encoding.GetBytes(). http://msdn.microsoft.com/en-us/library/system.text.encoding.aspx. Another approach would be to Base64 encode the hash and store the base64, but sine it still needs to be converted to/from base64 for the sue of the library, I see no benefit over varbinary/byte[]
Remus Rusanu