Serialize to a database

G

Guest

Hello All,

I want to serialize a hashtable to a database table to persist its values
between postbacks. The client requires that I not use ViewState, hence the
database.

The samples in MSDN show how to serialize a class that implements the
ICollection interface to a file. Does anyone know how to serialize to a
database table and conversely de-serialize from the table?

TIA,
 
P

Peter Rilling

All you have to do is serialize the contents as you normally would, which
would produce a set of bytes. Then encode those bytes into base64. When
save the data to some text field in the database.

Then reverse the process to de-serialize.
 
G

Guest

Thanks Peter.

I am not familiar with the encoding into base64. Do you know of an online
example?

--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


Peter Rilling said:
All you have to do is serialize the contents as you normally would, which
would produce a set of bytes. Then encode those bytes into base64. When
save the data to some text field in the database.

Then reverse the process to de-serialize.
 
G

Guest

Pater,

One more qeustion. Why encode in Base64?

Thanks,
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


Peter Rilling said:
All you have to do is serialize the contents as you normally would, which
would produce a set of bytes. Then encode those bytes into base64. When
save the data to some text field in the database.

Then reverse the process to de-serialize.
 
P

Peter Rilling

The reason is that when you serialize something, at least in binary format,
there are characters that may not play well with text fields. These are
often the control and extended characters. Base64 simple ensures that all
content can be interpreted as ASCII text. Although this may or may not be
necessary, I usually do this to prevent any subtle bugs when stored or
transmitting the data.

You can use the methods Convert.FromBase64String(...) and
Convert.ToBase64String(...).


Joe said:
Pater,

One more qeustion. Why encode in Base64?

Thanks,
 
B

Bruce Barker

if you use a binary field you can just store the serialized byte array. if
you serialize to xml, then a text field is fine.

-- bruce (sqlwork.com)



Joe said:
Pater,

One more qeustion. Why encode in Base64?

Thanks,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,120
Latest member
ShelaWalli
Top