Saturday, March 24, 2012

Serialize to a database

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,
--
Joe
VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA AutomationAll 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.
"Joe" <joeherro@.donotspam.yahoo.com> wrote in message
news:2528A3F3-A936-46F9-94D6-134C5146CD5E@.microsoft.com...
> 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,
> --
> Joe
> VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
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" wrote:

> 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.
>
> "Joe" <joeherro@.donotspam.yahoo.com> wrote in message
> news:2528A3F3-A936-46F9-94D6-134C5146CD5E@.microsoft.com...
>
>
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" wrote:

> 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.
>
> "Joe" <joeherro@.donotspam.yahoo.com> wrote in message
> news:2528A3F3-A936-46F9-94D6-134C5146CD5E@.microsoft.com...
>
>
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" <joeherro@.donotspam.yahoo.com> wrote in message
news:982AFEA2-C86B-4431-9006-D23298BF604A@.microsoft.com...
> 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" wrote:
>
Thank you very much. I aprpeciate it.
--
Joe
VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
"Peter Rilling" wrote:

> 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" <joeherro@.donotspam.yahoo.com> wrote in message
> news:982AFEA2-C86B-4431-9006-D23298BF604A@.microsoft.com...
>
>
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" <joeherro@.donotspam.yahoo.com> wrote in message
news:982AFEA2-C86B-4431-9006-D23298BF604A@.microsoft.com...
> 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" wrote:
>

0 comments:

Post a Comment