I want to send a lot of data from c# to my database, together with a calculated checksum as the last value, which should be compared to the one that the SQL Server's stored procedure will compute from those values.
To achieve this, I have tried a lot of different ways like the SQL built-in Checksum
method and different hashings, but either the C# and SQL compute a different value, or the hashing doesn't work with nvarchars and integers (fx. MD5 hashing) which is required for me.
Did anyone actually manage to do this, or know how to?
Reference to our failed MD5 attempt: SQL Server HASHBYTES conversion inconsistency?
here, the computed result is different than the c# one when it uses nvarchars
Hashing method:
Set @result = convert(nvarchar(32), hashbytes('MD5', @DataID + @Data1 + @Data2 + @Data3), 2)
Also, when you give the hashing method an integer as parameter (like DataID), it complains:
"Argument data type int is invalid for argument 2 of hashbytes function."