2

I am serializing a xml and compress to ToBase64String stores in the database as nvarchar, while loading decompress the string from 'FromBase64String' throws the error

"The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or a non-white space character among the padding characters."

I referred to this How to check for a valid Base64 encoded string but not worked for me ? is there anyway to remove unwanted characters from the string.

below is a part of serialized string

5gAAAB+LCAAAAAAABADsvQdgHEmWJSYvbcp7f0r1StfgdKEIgGATJNiQQBDswYjN5pLsHWlHIymrKoHKZVZlXWYWQMztnbz33nvvvffee++997 
Community
  • 1
  • 1
GANI
  • 2,013
  • 4
  • 35
  • 69
  • Did you try to deserialize a base64-string before uploading it to DB? Was there an error in that case? Also, how do you serialize the data? I do it via Convert.ToBase64String method and it works ok. – Dmitry Polyanitsa Jul 12 '12 at 06:51
  • 2
    Posting *part* of the serialized string doesn't really help. If you've got any examples which are *complete*, that would really help. My guess is that you may have hit the length limit for the field. – Jon Skeet Jul 12 '12 at 07:01
  • I tried to deserialize before saving to DB, it works fine over here,used Convert.ToBase64String to serialize the data – GANI Jul 12 '12 at 07:04
  • when i deserialize a string of length 500 works fine, when the length is > 2000 it breaks is there any other way to do this ? how to resolve this issue? – GANI Jul 12 '12 at 07:27
  • You are trying to solve this on the wrong end. Whatever program wrote the table column wrote garbage. Possibly because it is trying to write too much and it doesn't fit the column. You'll need to fix it. – Hans Passant Jul 12 '12 at 08:43
  • as the string size grows the deserialization fails is there any limit on this ?max size of sql nvarchar is 2gb so why there will be problem with database?do i need to change the type from nvarchar to someother type? please respond ASAP – GANI Jul 12 '12 at 15:32

0 Answers0