Showing posts with label serialize. Show all posts
Showing posts with label serialize. Show all posts

Monday, March 26, 2012

Serialization

Hi,

I have to serialize a class which consists of numerous members in it. I know that it can be serialized with the [Serializable] attribute. But my problem is that I wanna serialize only few members. Is there any way that allows us to serialize only few members in a class?

Please help.

Decorate the fields you want to exclude with [NonSerialized] .


You can include the [NonSerialized] attribute for the members which you do not wish to be serialized as shown below.

[Serializable]
class ABC
{
int x;
int y;
[NonSerialized]int z;//z will not be serializable.
}

I hopw this helped you.

SrikanthReddy.L

Serialization

Greetings,


i have two applications on two separate machines

In the first application i serialize an object into a text file ,so my question how can i transmit the text file by hard coding to the second application in order to deserialize the text file into the original object?

your help is highly appreciated

best regards

Hello,

How to: Deserialize an Object :http://msdn2.microsoft.com/en-us/library/fa420a9y.aspx


Greetings,

thank you for the support

i know how can i deserialize an object but my question is how can the second application get the textfile (file1.txt where the file1.txt is a serialized object serialized by the first application machine a)?

your help is highly appreciated


You have to tell the second application where it can find the textfile. If the name of the textfile is always the same, add a key in your config file that holds the name.

If the name changes dynamically and unpredictable you'll have to find a way to pass the values. If both applications are on the same machine you may use the windows message queue or a static file in your filesystem that holds your files.

If they are on different machines you may use either a webservice or a network connection over TCP or UDP.

Hope that helps,
Matthias :)


thank you for the support

i will try.

Serialization

Can we serialize the object which uses HashTables.

It depends on the type of object that you are storing in the Hashtable.

If you are storing objects like string (or whatever which is marked with attribute serializable), then you can look thro the objects to serialize them one by one.


r.ramkumar:

Can we serialize the object which uses HashTables.

Yes, as long as the indivdual objects in the hash table are serializable (as the previous poster points out). Then all you have to do is serialize your hashtable, you don't have to loop through, serializing each individual object. If you take a look at the definition of Hashtable athttp://msdn2.microsoft.com/en-us/library/system.collections.hashtable(VS.71).aspx you'll see that it's marked as [Serializabl] and it implements the ISerializable interface.

Most objects that you would wish to put into a hashtable are serializale. An example of something that isn't is a DataReader, and if you think about it, there's no way that a DataReader could be put into a stream of text since it holds a connection to the database. Connections (to anything) are perfect examples of things that aren't serializable.

Sometimes you create a custom class and try to serialize it (or save it to an asp.net State server, which requires that it be serializable) and you get an error that it's not serializable. Just try decorating your class with the [Serializable] attribute, for example

[Serializable]
public class MyClass
{
....blah, blah
}

(note that in vb you use angle brackets instead of straight brackets, ie, <Serializable> instead of [Serializable]


I just reread your post and realize that I misunderstood it. The object you want to serialize uses a hashtable (I thought you were just trying to serialize something of type Hashtable). My answer is the same but pay special attention to the last half, the part beginning "Sometimes you create a custom class..." which I think is what will really answer your question.

Saturday, March 24, 2012

Serialization of DataView

Hi

What is the best way to serialize Dataview object?
Where we can find the best implementation for the same

ThankI'm not sure that you can serialize a DataView. You can serialize a
DataSet.

"Shyam Remella" <murthy_rs@.sify.com> wrote in message
news:F082AD1B-512D-4E78-90CB-3F317A46DB80@.microsoft.com...
> Hi,
> What is the best way to serialize Dataview object?
> Where we can find the best implementation for the same?
> Thanks

Serialize

Hello,

What kind of objects are Serializable in Asp.Net 2.0 besides classes which I know they can.

Does anyone knows any good resource about Serialization in Asp.Net 2.0?

Thanks,

Miguel

These articles should tell you everything you could possibly want to know:

http://www.4guysfromrolla.com/webtech/012302-1.shtml

http://aspalliance.com/983

http://www.thescarms.com/dotnet/serializeable.asp

Hope this helps! Don't forget to mark the most helpful post asAnswer for the sake of future readers. Thanks


"By default, objects in .NET are not serializable. But the Microsoft? .NET Framework provides a standard, straightforward way to serialize and deserialize objects. In most cases, all you have to do is add the Serializable attribute"

http://msdn.microsoft.com/msdnmag/issues/04/10/AdvancedSerialization/

Serialize a base class?

Howdy,
A little background, using asp.net 2.0, i'm using a wizard object to create
a email interface for a user to email out their clientele, about 200 or so,
depending on the selection. The first step in the wizard is the email
selection, so it lists all the email accounts and distribution lists the
system has for the user, the user can select lists and/or individuals. I
then read through it all and throw it into an arraylist as a mailaddress
object. The next step in the wizard gives options of whether or not its
displays the selected recipients (including the ones in the lists), format
HTML vs Plain text, BCC the sender, etc. So I loop through all of the
selected emails in my arraylist to display which recipients the user is
emailing to. Here lies my issue.
I need the previously loaded arraylist of selected email addresses to still
be available. The only way i know how to do that is either throw it into a
session variable or the viewstate, both of which requires the class to be
serializable, which MailAddress isn't. I looked into Inheriting and trying
that but I got nowhere fast with that:
<Serializable()> Public Class MailAddress1
Inherits MailAddress
Public Sub New(ByVal email As String, ByVal display As String)
MyBase.New(email, display)
End Sub
End Class
I tried overriding the New sub but it wouldn't let me. So I instead moved
the collecting of email addresses to when the user presses Send. And i do a
lighter collection of the email addresses to a string for displaying their
selected recipients.
SO
I would like to only collect the email addresses once and use the same
arraylist multiple times, on multiple postbacks. Is this possible? I thought
about creating a new class to hold the email address, then transfer them
from my class to the mailaddress class when going to send, but that didnt
make much sens to me to do.
Thanks!!!I think you're stuck with
Create your own Class.
I would write one that had the constructor value needs for the MailAddress
class.
MailAddress (String) Initializes a new instance of the MailAddress
class using the specified address.
MailAddress (String, String) Initializes a new instance of the
MailAddress class using the specified address and display name.
MailAddress (String, String, Encoding)
I'd probably pick the second one.
(Serializable _)
public class MyEMailAddressInfo
property EmailAddress as string
property DisplayName as string
public static (shared in vb.net) GetMailAddress ( e as
MyEMailAddressInfo ) as MailAddress
and then create a collection of these
public class MyEmailAddressInfoCollection : List (Of MyEMailAddressInfo )
( use the inherit keyword instead of the c# ":" of course).
And I'd keep a copy of this object in the Session.
That's what I would do, look for other ideas from others.
Even if that class was serializable, you probably want to keep a "lite"
version of the values (aka the custom collection above) for either Session
or ViewState keeping, because of memory issues.
Keeping around alot of MailAddress objects, just because you need a bunch of
joe@.joes.com values seems non-frugal with the resources
Use the
public static (shared in vb.net) GetMailAddress ( e as MyEMailAddressInfo )
to delay getting those MailAddress objects you need when you actually need
them.
"David Lozzi" <dlozzi@.nospam.nospam> wrote in message
news:8D91BDDA-0C11-425B-8DB3-D1278E4B8C3D@.microsoft.com...
> Howdy,
> A little background, using asp.net 2.0, i'm using a wizard object to
create
> a email interface for a user to email out their clientele, about 200 or
so,
> depending on the selection. The first step in the wizard is the email
> selection, so it lists all the email accounts and distribution lists the
> system has for the user, the user can select lists and/or individuals. I
> then read through it all and throw it into an arraylist as a mailaddress
> object. The next step in the wizard gives options of whether or not its
> displays the selected recipients (including the ones in the lists), format
> HTML vs Plain text, BCC the sender, etc. So I loop through all of the
> selected emails in my arraylist to display which recipients the user is
> emailing to. Here lies my issue.
> I need the previously loaded arraylist of selected email addresses to
still
> be available. The only way i know how to do that is either throw it into a
> session variable or the viewstate, both of which requires the class to be
> serializable, which MailAddress isn't. I looked into Inheriting and trying
> that but I got nowhere fast with that:
> <Serializable()> Public Class MailAddress1
> Inherits MailAddress
> Public Sub New(ByVal email As String, ByVal display As String)
> MyBase.New(email, display)
> End Sub
> End Class
> I tried overriding the New sub but it wouldn't let me. So I instead moved
> the collecting of email addresses to when the user presses Send. And i do
a
> lighter collection of the email addresses to a string for displaying their
> selected recipients.
> SO
> I would like to only collect the email addresses once and use the same
> arraylist multiple times, on multiple postbacks. Is this possible? I
thought
> about creating a new class to hold the email address, then transfer them
> from my class to the mailaddress class when going to send, but that didnt
> make much sens to me to do.
> Thanks!!!
>

serialize class to the viewstate

I am trying to serialize a class called Order to the ViewState. Order has
one property called LineItems, which is an ArrayList. The ArrayList holds
instances of a class named LineItem. Bother Order and LineItem are marked
with the <Serializable> attribute.

When I attempt to serialize the class using this code:

Dim xs As XmlSerializer = New XmlSerializer(GetType(Order))

Dim sw As New StringWriter()

xs.Serialize(sw, _Order)

ViewState("LineItems") = sw.ToString()

On the line xs.Serialize(sw, _Order), I get an error that reads:

The type LineItem was not expected. Use the XmlInclude or SoapInclude
attribute to specify types that are not known statically.

What am I missing?

Thanks,

Craig BuchananYou may have to specify what the array list holds with the XmlElement
attribute.

I have a list that holds two different types and I had to do apply the
following to the array list:
<XmlElement(Type:=GetType(StringCriteriaField)),
XmlElement(Type:=GetType(IntegerCriteriaField))
"Craig Buchanan" <someone@.somewhere.com> wrote in message
news:#X3bk8R5DHA.504@.TK2MSFTNGP11.phx.gbl...
> I am trying to serialize a class called Order to the ViewState. Order has
> one property called LineItems, which is an ArrayList. The ArrayList holds
> instances of a class named LineItem. Bother Order and LineItem are marked
> with the <Serializable> attribute.
> When I attempt to serialize the class using this code:
> Dim xs As XmlSerializer = New XmlSerializer(GetType(Order))
> Dim sw As New StringWriter()
> xs.Serialize(sw, _Order)
> ViewState("LineItems") = sw.ToString()
> On the line xs.Serialize(sw, _Order), I get an error that reads:
> The type LineItem was not expected. Use the XmlInclude or SoapInclude
> attribute to specify types that are not known statically.
> What am I missing?
> Thanks,
> Craig Buchanan

Serialize DateTime

Hi -

I'm currently using a BinaryFormater to serialize my ObjectGraph. Private members of type string serialize and deserialise well however private members of type DateTime do not deserialize back into their original datetime values - something is lost.

Can someone direct me on solving this problem? For the moment I'm casting my DateTime values to string before serialization and then using DateTime.Parse(...) to get the string representation back to type DateTime. It works but I'd prefer the correct way I must be doing something wrong!

The following fragment (C#) is how i'm marking my class for serialization:

[Serializable()]
public class SessionData
{
private DateTime _sessionDate;

Thanks for any direction on this.How about serialising the Ticks property of your DateTime object? Then you can instantiate a new DateTime object from that single Ticks value ...

(I haven't tested this ... just thinking aloud.)
Thanks for the suggestion. That would probably work as it would convert the DateTime to a Long data type, but I'm wondering why the problem with DateTime ?

I'm sure the framework is designed to serialise DateTime without the need for casting (pretty stupid if this is not the case!) so what am I missing ?
Well, DateTime is a Struct ... so it's closer to a class than it is to a base type (such as a string or integer). Hence, I don't think serialising will be quite so automatic ... to serialise a class, you generally have to do a bit of work.

But, as to that "bit of work", I was just wondering aloud whether Ticks might make your job easier.

And I could be completely wrong ... 'tis just a suggestion :)

Serialize DataTable

This just doesn't make sense to me at all. I know you can't return a DataTable from a web service method. I know the work around is to return a DataSet instead.

The DataTable can't be serialized and that's by design, according to MSDN. But the DataSet can, and the DataSet contains DataTables (probably). A DataTable obviously gets serialized when you serialize a DataSet, so why can't you just deal with the DataTable?I haven't tried it, but the DataTable (according to MSDN Library) is serializable:

<Serializable>
Public Class DataTable
Inherits MarshalByValueComponent
Implements IListSource, ISupportInitialize, ISerializable

If you are talking about the .WriteXml() method, then that is a whole different thing since it is an implementation thing.
Not sure about that, I guess I mean this (http://support.microsoft.com/default.aspx?scid=kb;en-us;306134). Like I said it's easy enough to work around, I just don't understand why it's like that.

serialize datagrid properties

i want to serialize datagrid properties.. so that it can be retirved later
from other form and similiar datagrid can be generated. How can it be done ?Dear Vikram,
here are some links on datagrid serialization
1. XML Serialization in the .NET Framework
========================================
===
http://msdn.microsoft.com/library/d...y/en-us/dnexxml
/html/xml01202003.asp
2.
http://support.microsoft.com/defaul...desks%2Fwebcast
s%2Fen%2Fwc091202%2Fwct091202.asp
3. A Simple Recommender System - The Collaborative Network Library
========================================
==========================
http://www.codeproject.com/aspnet/collabnetwork.asp
You should be aware of this also.
4. Nine reasons not to use serialization
========================================
=
http://www.codeproject.com/dotnet/n...forumid=33017&e
xp=0&select=985675
Bye
Venkat_KL
For Anything and Everything, Please Let Me Know
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com
I mean serializing datagrid properties that is column porperties , header
porperrties etc. All these links point to dataset serialization...
"Venkat_KL" <venkat_kl@.yahoo.com> wrote in message
news:%230VQJ3GAGHA.272@.tk2msftngp13.phx.gbl...
> Dear Vikram,
> here are some links on datagrid serialization
> 1. XML Serialization in the .NET Framework
> ========================================
===
> http://msdn.microsoft.com/library/d...y/en-us/dnexxml
> /html/xml01202003.asp
> 2.
> http://support.microsoft.com/defaul...desks%2Fwebcast
> s%2Fen%2Fwc091202%2Fwct091202.asp
> 3. A Simple Recommender System - The Collaborative Network Library
> ========================================
==========================
> http://www.codeproject.com/aspnet/collabnetwork.asp
> You should be aware of this also.
> 4. Nine reasons not to use serialization
> ========================================
=
> http://www.codeproject.com/dotnet/n...forumid=33017&e
> xp=0&select=985675
> Bye
> Venkat_KL
>
> For Anything and Everything, Please Let Me Know
> --
> Sent via .NET Newsgroups
> http://www.dotnetnewsgroups.com

Serialize Object in Session?

Is it recommended to serialize a custom object when putting it in session?

I have a User object with properties ID, FirstName, LastName, and an
array of Permissions which I would like to keep in session. Should I
first serialize it to put it in session? I read that this is not
necessary, but I'm wondering about memory usage and performance. I
realize that serializing/deserializing the object will take time, but
will the serialized object consume less memory than the non serialized
object? If so, will it be significant. Thanks.> Is it recommended to serialize a custom object when putting it in session?

No.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Neither a follower nor a lender be.

"nick" <nickgieschen@.hotmail.com> wrote in message
news:305cab98.0308201022.164480d@.posting.google.co m...
> Is it recommended to serialize a custom object when putting it in session?
> I have a User object with properties ID, FirstName, LastName, and an
> array of Permissions which I would like to keep in session. Should I
> first serialize it to put it in session? I read that this is not
> necessary, but I'm wondering about memory usage and performance. I
> realize that serializing/deserializing the object will take time, but
> will the serialized object consume less memory than the non serialized
> object? If so, will it be significant. Thanks.
Serialize objects can recreate themselves from the stream.

So usually serialized representation of the object takes up more space than
object itself.

George.

"nick" <nickgieschen@.hotmail.com> wrote in message
news:305cab98.0308201022.164480d@.posting.google.co m...
> Is it recommended to serialize a custom object when putting it in session?
> I have a User object with properties ID, FirstName, LastName, and an
> array of Permissions which I would like to keep in session. Should I
> first serialize it to put it in session? I read that this is not
> necessary, but I'm wondering about memory usage and performance. I
> realize that serializing/deserializing the object will take time, but
> will the serialized object consume less memory than the non serialized
> object? If so, will it be significant. Thanks.

Serialize object to database example

Xref: kermit microsoft.public.dotnet.framework.aspnet:261279
Does anyone have an example of serializing an object to a database table?Hi Marcel,
I made this sample saterday morning after some arguing in the language.vb
group
It is complete most is to prove it works.
The sample is windowforms, so that have you to change it yourself a little
bit, however is serialize and it deserialize.
I hope it was what you where looking for
Cor
\\\
Private WithEvents combobox1 As New ComboBox
Private strt As Boolean
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim Belgen As New BelgenCollection
Belgen.Add(New Belg(New String() {"Lambiek", "Man", "Jenever"}))
Belgen.Add(New Belg(New String() {"Sidonia", "Vrouw", "Likeur"}))
Belgen.Add(New Belg(New String() {"Suske", "Jongen", "Cola"}))
Belgen.Add(New Belg(New String() {"Wiske", "Meisje", "Limonade"}))
Belgen.Add(New Belg(New String() {"Jerom", "Jongeman", "Bier"}))
Dim Serializer As New
Xml.Serialization. XmlSerializer(GetType(BelgenCollection))
Dim sw As New System.IO.StringWriter
Serializer.Serialize(sw, Belgen)
Dim ds As New DataSet
Dim dt As New DataTable("Jay")
Dim dc As New DataColumn("Charles")
'This part only for Jay and Charles if he wants
dt.Columns.Add(dc)
ds.Tables.Add(dt)
dt.Rows.Add(dt.NewRow)
ds.Tables(0).Rows(0)(0) = sw.ToString
ds.WriteXml("c:\test1\charles.xml")
Dim dsJay As New DataSet
dsJay.ReadXml("c:\test1\Charles.xml")
Dim Charles As String = dsJay.Tables(0).Rows(0)(0).ToString
'End Jay part
Dim Deserializer As New Xml.Serialization.XmlSerializer _
(GetType(BelgenCollection))
Dim sr As New System.IO.StringReader(Charles)
Dim reader As New System.Xml.XmlTextReader(sr)
Dim Vlamingen As BelgenCollection
Vlamingen = CType(Deserializer.Deserialize(reader), _
BelgenCollection)
Me.Controls.Add(combobox1)
combobox1.DataSource = Vlamingen
strt = True
End Sub
Private Sub combobox1_SelectedIndexChanged(ByVal _
sender As Object, ByVal e As System.EventArgs) _
Handles combobox1.SelectedIndexChanged
If strt = True Then
MessageBox.Show(DirectCast(combobox1.SelectedValue, Belg).drank)
End If
End Sub
End Class
///
\\\
Public Class Belg
Public Naam As String
Public sex As String
Public drank As String
Public Sub New()
End Sub
Public Sub New(ByVal fill As String())
Naam = fill(0)
sex = fill(1)
drank = fill(2)
End Sub
Public Overrides Function tostring() As String
Return Naam
End Function
End Class
Public Class BelgenCollection
Inherits System.Collections.CollectionBase
Default Public Overloads ReadOnly _
Property Item(ByVal index As Integer) As Belg
Get
Return DirectCast(list.Item(index), Belg)
End Get
End Property
Public Sub Add(ByVal aBelg As Belg)
List.Add(aBelg)
End Sub
End Class
///
Thank you Cor,
I was planning to use the BinaryFormatter class. I would then store the
object in binary format in a varbinary column in a general table.
Is this a common practice? Any further tips?
Marcel
I
"Cor Ligthert" <notfirstname@.planet.nl> wrote in message
news:OxujYixIEHA.940@.tk2msftngp13.phx.gbl...
> Hi Marcel,
> I made this sample saterday morning after some arguing in the language.vb
> group
> It is complete most is to prove it works.
> The sample is windowforms, so that have you to change it yourself a little
> bit, however is serialize and it deserialize.
> I hope it was what you where looking for
> Cor
> \\\
> Private WithEvents combobox1 As New ComboBox
> Private strt As Boolean
> Private Sub Form1_Load(ByVal sender As Object, _
> ByVal e As System.EventArgs) Handles MyBase.Load
> Dim Belgen As New BelgenCollection
> Belgen.Add(New Belg(New String() {"Lambiek", "Man", "Jenever"
}))
> Belgen.Add(New Belg(New String() {"Sidonia", "Vrouw", "Likeur
"}))
> Belgen.Add(New Belg(New String() {"Suske", "Jongen", "Cola"})
)
> Belgen.Add(New Belg(New String() {"Wiske", "Meisje", "Limonad
e"}))
> Belgen.Add(New Belg(New String() {"Jerom", "Jongeman", "Bier"
}))
> Dim Serializer As New
> Xml.Serialization. XmlSerializer(GetType(BelgenCollection))
> Dim sw As New System.IO.StringWriter
> Serializer.Serialize(sw, Belgen)
> Dim ds As New DataSet
> Dim dt As New DataTable("Jay")
> Dim dc As New DataColumn("Charles")
> 'This part only for Jay and Charles if he wants
> dt.Columns.Add(dc)
> ds.Tables.Add(dt)
> dt.Rows.Add(dt.NewRow)
> ds.Tables(0).Rows(0)(0) = sw.ToString
> ds.WriteXml("c:\test1\charles.xml")
> Dim dsJay As New DataSet
> dsJay.ReadXml("c:\test1\Charles.xml")
> Dim Charles As String = dsJay.Tables(0).Rows(0)(0).ToString
> 'End Jay part
> Dim Deserializer As New Xml.Serialization.XmlSerializer _
> (GetType(BelgenCollection))
> Dim sr As New System.IO.StringReader(Charles)
> Dim reader As New System.Xml.XmlTextReader(sr)
> Dim Vlamingen As BelgenCollection
> Vlamingen = CType(Deserializer.Deserialize(reader), _
> BelgenCollection)
> Me.Controls.Add(combobox1)
> combobox1.DataSource = Vlamingen
> strt = True
> End Sub
> Private Sub combobox1_SelectedIndexChanged(ByVal _
> sender As Object, ByVal e As System.EventArgs) _
> Handles combobox1.SelectedIndexChanged
> If strt = True Then
> MessageBox.Show(DirectCast(combobox1.SelectedValue,
Belg).drank)
> End If
> End Sub
> End Class
> ///
> \\\
> Public Class Belg
> Public Naam As String
> Public sex As String
> Public drank As String
> Public Sub New()
> End Sub
> Public Sub New(ByVal fill As String())
> Naam = fill(0)
> sex = fill(1)
> drank = fill(2)
> End Sub
> Public Overrides Function tostring() As String
> Return Naam
> End Function
> End Class
> Public Class BelgenCollection
> Inherits System.Collections.CollectionBase
> Default Public Overloads ReadOnly _
> Property Item(ByVal index As Integer) As Belg
> Get
> Return DirectCast(list.Item(index), Belg)
> End Get
> End Property
> Public Sub Add(ByVal aBelg As Belg)
> List.Add(aBelg)
> End Sub
> End Class
> ///
>

Serialize object to database example

Does anyone have an example of serializing an object to a database table?Hi Marcel,

I made this sample saterday morning after some arguing in the language.vb
group
It is complete most is to prove it works.

The sample is windowforms, so that have you to change it yourself a little
bit, however is serialize and it deserialize.

I hope it was what you where looking for

Cor

\\\
Private WithEvents combobox1 As New ComboBox
Private strt As Boolean
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim Belgen As New BelgenCollection
Belgen.Add(New Belg(New String() {"Lambiek", "Man", "Jenever"}))
Belgen.Add(New Belg(New String() {"Sidonia", "Vrouw", "Likeur"}))
Belgen.Add(New Belg(New String() {"Suske", "Jongen", "Cola"}))
Belgen.Add(New Belg(New String() {"Wiske", "Meisje", "Limonade"}))
Belgen.Add(New Belg(New String() {"Jerom", "Jongeman", "Bier"}))
Dim Serializer As New
Xml.Serialization.XmlSerializer(GetType(BelgenColl ection))
Dim sw As New System.IO.StringWriter
Serializer.Serialize(sw, Belgen)
Dim ds As New DataSet
Dim dt As New DataTable("Jay")
Dim dc As New DataColumn("Charles")
'This part only for Jay and Charles if he wants
dt.Columns.Add(dc)
ds.Tables.Add(dt)
dt.Rows.Add(dt.NewRow)
ds.Tables(0).Rows(0)(0) = sw.ToString
ds.WriteXml("c:\test1\charles.xml")
Dim dsJay As New DataSet
dsJay.ReadXml("c:\test1\Charles.xml")
Dim Charles As String = dsJay.Tables(0).Rows(0)(0).ToString
'End Jay part
Dim Deserializer As New Xml.Serialization.XmlSerializer _
(GetType(BelgenCollection))
Dim sr As New System.IO.StringReader(Charles)
Dim reader As New System.Xml.XmlTextReader(sr)
Dim Vlamingen As BelgenCollection
Vlamingen = CType(Deserializer.Deserialize(reader), _
BelgenCollection)
Me.Controls.Add(combobox1)
combobox1.DataSource = Vlamingen
strt = True
End Sub
Private Sub combobox1_SelectedIndexChanged(ByVal _
sender As Object, ByVal e As System.EventArgs) _
Handles combobox1.SelectedIndexChanged
If strt = True Then
MessageBox.Show(DirectCast(combobox1.SelectedValue , Belg).drank)
End If
End Sub
End Class
///
\\\
Public Class Belg
Public Naam As String
Public sex As String
Public drank As String
Public Sub New()
End Sub
Public Sub New(ByVal fill As String())
Naam = fill(0)
sex = fill(1)
drank = fill(2)
End Sub
Public Overrides Function tostring() As String
Return Naam
End Function
End Class
Public Class BelgenCollection
Inherits System.Collections.CollectionBase
Default Public Overloads ReadOnly _
Property Item(ByVal index As Integer) As Belg
Get
Return DirectCast(list.Item(index), Belg)
End Get
End Property
Public Sub Add(ByVal aBelg As Belg)
List.Add(aBelg)
End Sub
End Class
///
Thank you Cor,
I was planning to use the BinaryFormatter class. I would then store the
object in binary format in a varbinary column in a general table.
Is this a common practice? Any further tips?
Marcel
I
"Cor Ligthert" <notfirstname@.planet.nl> wrote in message
news:OxujYixIEHA.940@.tk2msftngp13.phx.gbl...
> Hi Marcel,
> I made this sample saterday morning after some arguing in the language.vb
> group
> It is complete most is to prove it works.
> The sample is windowforms, so that have you to change it yourself a little
> bit, however is serialize and it deserialize.
> I hope it was what you where looking for
> Cor
> \\\
> Private WithEvents combobox1 As New ComboBox
> Private strt As Boolean
> Private Sub Form1_Load(ByVal sender As Object, _
> ByVal e As System.EventArgs) Handles MyBase.Load
> Dim Belgen As New BelgenCollection
> Belgen.Add(New Belg(New String() {"Lambiek", "Man", "Jenever"}))
> Belgen.Add(New Belg(New String() {"Sidonia", "Vrouw", "Likeur"}))
> Belgen.Add(New Belg(New String() {"Suske", "Jongen", "Cola"}))
> Belgen.Add(New Belg(New String() {"Wiske", "Meisje", "Limonade"}))
> Belgen.Add(New Belg(New String() {"Jerom", "Jongeman", "Bier"}))
> Dim Serializer As New
> Xml.Serialization.XmlSerializer(GetType(BelgenColl ection))
> Dim sw As New System.IO.StringWriter
> Serializer.Serialize(sw, Belgen)
> Dim ds As New DataSet
> Dim dt As New DataTable("Jay")
> Dim dc As New DataColumn("Charles")
> 'This part only for Jay and Charles if he wants
> dt.Columns.Add(dc)
> ds.Tables.Add(dt)
> dt.Rows.Add(dt.NewRow)
> ds.Tables(0).Rows(0)(0) = sw.ToString
> ds.WriteXml("c:\test1\charles.xml")
> Dim dsJay As New DataSet
> dsJay.ReadXml("c:\test1\Charles.xml")
> Dim Charles As String = dsJay.Tables(0).Rows(0)(0).ToString
> 'End Jay part
> Dim Deserializer As New Xml.Serialization.XmlSerializer _
> (GetType(BelgenCollection))
> Dim sr As New System.IO.StringReader(Charles)
> Dim reader As New System.Xml.XmlTextReader(sr)
> Dim Vlamingen As BelgenCollection
> Vlamingen = CType(Deserializer.Deserialize(reader), _
> BelgenCollection)
> Me.Controls.Add(combobox1)
> combobox1.DataSource = Vlamingen
> strt = True
> End Sub
> Private Sub combobox1_SelectedIndexChanged(ByVal _
> sender As Object, ByVal e As System.EventArgs) _
> Handles combobox1.SelectedIndexChanged
> If strt = True Then
> MessageBox.Show(DirectCast(combobox1.SelectedValue ,
Belg).drank)
> End If
> End Sub
> End Class
> ///
> \\\
> Public Class Belg
> Public Naam As String
> Public sex As String
> Public drank As String
> Public Sub New()
> End Sub
> Public Sub New(ByVal fill As String())
> Naam = fill(0)
> sex = fill(1)
> drank = fill(2)
> End Sub
> Public Overrides Function tostring() As String
> Return Naam
> End Function
> End Class
> Public Class BelgenCollection
> Inherits System.Collections.CollectionBase
> Default Public Overloads ReadOnly _
> Property Item(ByVal index As Integer) As Belg
> Get
> Return DirectCast(list.Item(index), Belg)
> End Get
> End Property
> Public Sub Add(ByVal aBelg As Belg)
> List.Add(aBelg)
> End Sub
> End Class
> ///

Serialize session state & OutOfMemoryError?

I have an application running on a 3 server webfarm running Windows 2003 with
SQLServer Session state. After running for several hours, I started getting
the following error. When I access each app individually, only one of the
servers seems to return this error when I step through a sequence. I was
told that I'm trying to store an object not marked as Serializable but I've
tested this on a dev machine storing session variables without any problems,
plus it works for several hours before I have issues. I think something else
is the root of this error but I don't know where to look exactly.

Server Error in '/' Application.
------------------------

Unable to serialize the session state. Please note that non-serializable
objects or MarshalByRef objects are not permitted when session state mode is
'StateServer' or 'SQLServer'.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.Web.HttpException: Unable to serialize the session
state. Please note that non-serializable objects or MarshalByRef objects are
not permitted when session state mode is 'StateServer' or 'SQLServer'.

Source Error:

An unhandled exception was generated during the execution of the current web
request. Information regarding the origin and location of the exception can
be identified using the exception stack trace below.

Stack Trace:

[OutOfMemoryException: Exception of type System.OutOfMemoryException was
thrown.]

[HttpException (0x80004005): Unable to serialize the session state. Please
note that non-serializable objects or MarshalByRef objects are not permitted
when session state mode is 'StateServer' or 'SQLServer'.]
System.Web.Util.AltSerialization.WriteValueToStrea m(Object value,
BinaryWriter writer) +1711
System.Web.SessionState.SessionDictionary.Serializ e(BinaryWriter writer)
+148
System.Web.SessionState.StateClientManager.Seriali ze(SessionStateItem
item, Stream stream) +146

System.Web.SessionState.SqlStateClientManager.Syst em.Web.SessionState.IStateClientManager.Set(String id, SessionStateItem item, Boolean inStorage) +126
System.Web.SessionState.SessionStateModule.OnRelea seState(Object source,
EventArgs eventArgs) +465

System.Web.SyncEventExecutionStep.System.Web.HttpA pplication+IExecutionStep.Execute() +60
System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean&
completedSynchronously) +87many objects are serialiable until an unserialiable property is set, or an
unserialiable object is added.

-- bruce (sqlwork.com)

"Dave" <Dave@.discussions.microsoft.com> wrote in message
news:F64A9CC1-7B9B-411A-A8FB-1B9CF6C0FFEB@.microsoft.com...
>I have an application running on a 3 server webfarm running Windows 2003
>with
> SQLServer Session state. After running for several hours, I started
> getting
> the following error. When I access each app individually, only one of the
> servers seems to return this error when I step through a sequence. I was
> told that I'm trying to store an object not marked as Serializable but
> I've
> tested this on a dev machine storing session variables without any
> problems,
> plus it works for several hours before I have issues. I think something
> else
> is the root of this error but I don't know where to look exactly.
> Server Error in '/' Application.
> ------------------------
> Unable to serialize the session state. Please note that non-serializable
> objects or MarshalByRef objects are not permitted when session state mode
> is
> 'StateServer' or 'SQLServer'.
> Description: An unhandled exception occurred during the execution of the
> current web request. Please review the stack trace for more information
> about
> the error and where it originated in the code.
> Exception Details: System.Web.HttpException: Unable to serialize the
> session
> state. Please note that non-serializable objects or MarshalByRef objects
> are
> not permitted when session state mode is 'StateServer' or 'SQLServer'.
> Source Error:
> An unhandled exception was generated during the execution of the current
> web
> request. Information regarding the origin and location of the exception
> can
> be identified using the exception stack trace below.
> Stack Trace:
>
> [OutOfMemoryException: Exception of type System.OutOfMemoryException was
> thrown.]
> [HttpException (0x80004005): Unable to serialize the session state. Please
> note that non-serializable objects or MarshalByRef objects are not
> permitted
> when session state mode is 'StateServer' or 'SQLServer'.]
> System.Web.Util.AltSerialization.WriteValueToStrea m(Object value,
> BinaryWriter writer) +1711
> System.Web.SessionState.SessionDictionary.Serializ e(BinaryWriter writer)
> +148
> System.Web.SessionState.StateClientManager.Seriali ze(SessionStateItem
> item, Stream stream) +146
> System.Web.SessionState.SqlStateClientManager.Syst em.Web.SessionState.IStateClientManager.Set(String
> id, SessionStateItem item, Boolean inStorage) +126
> System.Web.SessionState.SessionStateModule.OnRelea seState(Object source,
> EventArgs eventArgs) +465
> System.Web.SyncEventExecutionStep.System.Web.HttpA pplication+IExecutionStep.Execute()
> +60
> System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean&
> completedSynchronously) +87
Bruce,

Sorry, can you expand on that? If I'm adding a dataset to my session and a
few hours into the day I start to get this error on one of the servers, I'm
not sure how that it explains the problem

Thanks.

"Bruce Barker" wrote:

> many objects are serialiable until an unserialiable property is set, or an
> unserialiable object is added.
>
> -- bruce (sqlwork.com)
>
> "Dave" <Dave@.discussions.microsoft.com> wrote in message
> news:F64A9CC1-7B9B-411A-A8FB-1B9CF6C0FFEB@.microsoft.com...
> >I have an application running on a 3 server webfarm running Windows 2003
> >with
> > SQLServer Session state. After running for several hours, I started
> > getting
> > the following error. When I access each app individually, only one of the
> > servers seems to return this error when I step through a sequence. I was
> > told that I'm trying to store an object not marked as Serializable but
> > I've
> > tested this on a dev machine storing session variables without any
> > problems,
> > plus it works for several hours before I have issues. I think something
> > else
> > is the root of this error but I don't know where to look exactly.
> > Server Error in '/' Application.
> > ------------------------
> > Unable to serialize the session state. Please note that non-serializable
> > objects or MarshalByRef objects are not permitted when session state mode
> > is
> > 'StateServer' or 'SQLServer'.
> > Description: An unhandled exception occurred during the execution of the
> > current web request. Please review the stack trace for more information
> > about
> > the error and where it originated in the code.
> > Exception Details: System.Web.HttpException: Unable to serialize the
> > session
> > state. Please note that non-serializable objects or MarshalByRef objects
> > are
> > not permitted when session state mode is 'StateServer' or 'SQLServer'.
> > Source Error:
> > An unhandled exception was generated during the execution of the current
> > web
> > request. Information regarding the origin and location of the exception
> > can
> > be identified using the exception stack trace below.
> > Stack Trace:
> > [OutOfMemoryException: Exception of type System.OutOfMemoryException was
> > thrown.]
> > [HttpException (0x80004005): Unable to serialize the session state. Please
> > note that non-serializable objects or MarshalByRef objects are not
> > permitted
> > when session state mode is 'StateServer' or 'SQLServer'.]
> > System.Web.Util.AltSerialization.WriteValueToStrea m(Object value,
> > BinaryWriter writer) +1711
> > System.Web.SessionState.SessionDictionary.Serializ e(BinaryWriter writer)
> > +148
> > System.Web.SessionState.StateClientManager.Seriali ze(SessionStateItem
> > item, Stream stream) +146
> > System.Web.SessionState.SqlStateClientManager.Syst em.Web.SessionState.IStateClientManager.Set(String
> > id, SessionStateItem item, Boolean inStorage) +126
> > System.Web.SessionState.SessionStateModule.OnRelea seState(Object source,
> > EventArgs eventArgs) +465
> > System.Web.SyncEventExecutionStep.System.Web.HttpA pplication+IExecutionStep.Execute()
> > +60
> > System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean&
> > completedSynchronously) +87
>

Serialize session state & OutOfMemoryError?

I have an application running on a 3 server webfarm running Windows 2003 wit
h
SQLServer Session state. After running for several hours, I started getting
the following error. When I access each app individually, only one of the
servers seems to return this error when I step through a sequence. I was
told that I'm trying to store an object not marked as Serializable but I've
tested this on a dev machine storing session variables without any problems,
plus it works for several hours before I have issues. I think something els
e
is the root of this error but I don't know where to look exactly.
Server Error in '/' Application.
----
--
Unable to serialize the session state. Please note that non-serializable
objects or MarshalByRef objects are not permitted when session state mode is
'StateServer' or 'SQLServer'.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information abou
t
the error and where it originated in the code.
Exception Details: System.Web.HttpException: Unable to serialize the session
state. Please note that non-serializable objects or MarshalByRef objects are
not permitted when session state mode is 'StateServer' or 'SQLServer'.
Source Error:
An unhandled exception was generated during the execution of the current web
request. Information regarding the origin and location of the exception can
be identified using the exception stack trace below.
Stack Trace:
[OutOfMemoryException: Exception of type System.OutOfMemoryException was
thrown.]
[HttpException (0x80004005): Unable to serialize the session state. Please
note that non-serializable objects or MarshalByRef objects are not permitted
when session state mode is 'StateServer' or 'SQLServer'.]
System.Web.Util.AltSerialization.WriteValueToStream(Object value,
BinaryWriter writer) +1711
System.Web.SessionState.SessionDictionary.Serialize(BinaryWriter writer)
+148
System.Web.SessionState.StateClientManager.Serialize(SessionStateItem
item, Stream stream) +146
System.Web.SessionState.SqlStateClientManager.System.Web.SessionState.IState
ClientManager.Set(String id, SessionStateItem item, Boolean inStorage) +126
System.Web.SessionState.SessionStateModule.OnReleaseState(Object source,
EventArgs eventArgs) +465
System.Web.SyncEventExecutionStep.System.Web.HttpApplication+IExecutionStep.
Execute() +60
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
completedSynchronously) +87many objects are serialiable until an unserialiable property is set, or an
unserialiable object is added.
-- bruce (sqlwork.com)
"Dave" <Dave@.discussions.microsoft.com> wrote in message
news:F64A9CC1-7B9B-411A-A8FB-1B9CF6C0FFEB@.microsoft.com...
>I have an application running on a 3 server webfarm running Windows 2003
>with
> SQLServer Session state. After running for several hours, I started
> getting
> the following error. When I access each app individually, only one of the
> servers seems to return this error when I step through a sequence. I was
> told that I'm trying to store an object not marked as Serializable but
> I've
> tested this on a dev machine storing session variables without any
> problems,
> plus it works for several hours before I have issues. I think something
> else
> is the root of this error but I don't know where to look exactly.
> Server Error in '/' Application.
> ----
--
> Unable to serialize the session state. Please note that non-serializable
> objects or MarshalByRef objects are not permitted when session state mode
> is
> 'StateServer' or 'SQLServer'.
> Description: An unhandled exception occurred during the execution of the
> current web request. Please review the stack trace for more information
> about
> the error and where it originated in the code.
> Exception Details: System.Web.HttpException: Unable to serialize the
> session
> state. Please note that non-serializable objects or MarshalByRef objects
> are
> not permitted when session state mode is 'StateServer' or 'SQLServer'.
> Source Error:
> An unhandled exception was generated during the execution of the current
> web
> request. Information regarding the origin and location of the exception
> can
> be identified using the exception stack trace below.
> Stack Trace:
>
> [OutOfMemoryException: Exception of type System.OutOfMemoryException was
> thrown.]
> [HttpException (0x80004005): Unable to serialize the session state. Please
> note that non-serializable objects or MarshalByRef objects are not
> permitted
> when session state mode is 'StateServer' or 'SQLServer'.]
> System.Web.Util.AltSerialization.WriteValueToStream(Object value,
> BinaryWriter writer) +1711
> System.Web.SessionState.SessionDictionary.Serialize(BinaryWriter writer)
> +148
> System.Web.SessionState.StateClientManager.Serialize(SessionStateItem
> item, Stream stream) +146
> System.Web.SessionState.SqlStateClientManager.System.Web.SessionState.ISta
teClientManager.Set(String
> id, SessionStateItem item, Boolean inStorage) +126
> System.Web.SessionState.SessionStateModule.OnReleaseState(Object source,
> EventArgs eventArgs) +465
> System.Web.SyncEventExecutionStep.System.Web.HttpApplication+IExecutionSte
p.Execute()
> +60
> System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
> completedSynchronously) +87
>
>
Bruce,
Sorry, can you expand on that? If I'm adding a dataset to my session and a
few hours into the day I start to get this error on one of the servers, I'm
not sure how that it explains the problem
Thanks.
"Bruce Barker" wrote:

> many objects are serialiable until an unserialiable property is set, or an
> unserialiable object is added.
>
> -- bruce (sqlwork.com)
>
> "Dave" <Dave@.discussions.microsoft.com> wrote in message
> news:F64A9CC1-7B9B-411A-A8FB-1B9CF6C0FFEB@.microsoft.com...
>
>

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...
> > 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
>
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...
> > 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
>
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:
>> 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...
>> > 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
>>
>>
>
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...
> > 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...
> >> > 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
> >>
> >>
> >>
>
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:
>> 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...
>> > 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
>>
>>
>

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:
>

serialize to SQL Server Blob instead of XML serialize

I've been experiencing problems on some computers with XML Serialization. On
some computers the files do not get created on the web server's hard drive
and it's been driving me nuts trying to figure it out.
I store navigation history and application state in object collections and
save this upon application exit by doing an XML.Serialize.
I'd like to serialize directly to SQL Server instead. Can I create a stream
object to be used by SQL Server with serialization?
ThanksYeah, this is the basics (DT is just an object I'm taking from session and
serializing):
Dim ms As New MemoryStream
ms = SerializeDT(CType(Session("DT"), DTProcess))
Dim da() As Byte
da = ms.ToArray
cmd.Parameters("@.DesktopData").Value = da
SqlConnection1.Open()
cmd.ExecuteNonQuery()
SqlConnection1.Close()
Public Shared Function SerializeDT(ByVal DTSource As DTProcess) As
MemoryStream
Dim ms As New MemoryStream
Dim formatter As New BinaryFormatter
formatter.Serialize(ms, DTSource)
ms.Position = 0
Return ms
End Function
-John Oakes
"Gordz" <joeblow@.aol.com> wrote in message
news:10c96ar3sr73f4@.corp.supernews.com...
> I've been experiencing problems on some computers with XML Serialization.
On
> some computers the files do not get created on the web server's hard drive
> and it's been driving me nuts trying to figure it out.
> I store navigation history and application state in object collections and
> save this upon application exit by doing an XML.Serialize.
> I'd like to serialize directly to SQL Server instead. Can I create a
stream
> object to be used by SQL Server with serialization?
> Thanks
>
thanks John.
I've never used binary objects in SQL before.
Where exactly is your data "@.DesktopData" stored in the database? Do you
have a field already defined?
Cheers,
Gord
"John Oakes" <john@.nospam.networkproductions.net> wrote in message
news:OwaYP%23KTEHA.1416@.TK2MSFTNGP12.phx.gbl...
Yeah, this is the basics (DT is just an object I'm taking from session and
serializing):
Dim ms As New MemoryStream
ms = SerializeDT(CType(Session("DT"), DTProcess))
Dim da() As Byte
da = ms.ToArray
cmd.Parameters("@.DesktopData").Value = da
SqlConnection1.Open()
cmd.ExecuteNonQuery()
SqlConnection1.Close()
Public Shared Function SerializeDT(ByVal DTSource As DTProcess) As
MemoryStream
Dim ms As New MemoryStream
Dim formatter As New BinaryFormatter
formatter.Serialize(ms, DTSource)
ms.Position = 0
Return ms
End Function
-John Oakes
"Gordz" <joeblow@.aol.com> wrote in message
news:10c96ar3sr73f4@.corp.supernews.com...
> I've been experiencing problems on some computers with XML Serialization.
On
> some computers the files do not get created on the web server's hard drive
> and it's been driving me nuts trying to figure it out.
> I store navigation history and application state in object collections and
> save this upon application exit by doing an XML.Serialize.
> I'd like to serialize directly to SQL Server instead. Can I create a
stream
> object to be used by SQL Server with serialization?
> Thanks
>
Yes, I have a field defined. The datatype is image, which is
variable-length binary data from 0 through 231-1 (2,147,483,647) bytes.
-John Oakes
"Gordz" <joeblow@.aol.com> wrote in message
news:10c9fasr23jm702@.corp.supernews.com...
> thanks John.
> I've never used binary objects in SQL before.
> Where exactly is your data "@.DesktopData" stored in the database? Do you
> have a field already defined?
> Cheers,
> Gord
> "John Oakes" <john@.nospam.networkproductions.net> wrote in message
> news:OwaYP%23KTEHA.1416@.TK2MSFTNGP12.phx.gbl...
> Yeah, this is the basics (DT is just an object I'm taking from session and
> serializing):
> Dim ms As New MemoryStream
> ms = SerializeDT(CType(Session("DT"), DTProcess))
> Dim da() As Byte
> da = ms.ToArray
> cmd.Parameters("@.DesktopData").Value = da
> SqlConnection1.Open()
> cmd.ExecuteNonQuery()
> SqlConnection1.Close()
> Public Shared Function SerializeDT(ByVal DTSource As DTProcess) As
> MemoryStream
> Dim ms As New MemoryStream
> Dim formatter As New BinaryFormatter
> formatter.Serialize(ms, DTSource)
> ms.Position = 0
> Return ms
> End Function
> -John Oakes
>
> "Gordz" <joeblow@.aol.com> wrote in message
> news:10c96ar3sr73f4@.corp.supernews.com...
Serialization.
> On
drive
and
> stream
>
>

serialize to SQL Server Blob instead of XML serialize

I've been experiencing problems on some computers with XML Serialization. On
some computers the files do not get created on the web server's hard drive
and it's been driving me nuts trying to figure it out.

I store navigation history and application state in object collections and
save this upon application exit by doing an XML.Serialize.

I'd like to serialize directly to SQL Server instead. Can I create a stream
object to be used by SQL Server with serialization?

ThanksYeah, this is the basics (DT is just an object I'm taking from session and
serializing):

Dim ms As New MemoryStream
ms = SerializeDT(CType(Session("DT"), DTProcess))
Dim da() As Byte
da = ms.ToArray
cmd.Parameters("@.DesktopData").Value = da
SqlConnection1.Open()
cmd.ExecuteNonQuery()
SqlConnection1.Close()

Public Shared Function SerializeDT(ByVal DTSource As DTProcess) As
MemoryStream
Dim ms As New MemoryStream
Dim formatter As New BinaryFormatter
formatter.Serialize(ms, DTSource)
ms.Position = 0
Return ms
End Function

-John Oakes

"Gordz" <joeblow@.aol.com> wrote in message
news:10c96ar3sr73f4@.corp.supernews.com...
> I've been experiencing problems on some computers with XML Serialization.
On
> some computers the files do not get created on the web server's hard drive
> and it's been driving me nuts trying to figure it out.
> I store navigation history and application state in object collections and
> save this upon application exit by doing an XML.Serialize.
> I'd like to serialize directly to SQL Server instead. Can I create a
stream
> object to be used by SQL Server with serialization?
> Thanks
thanks John.

I've never used binary objects in SQL before.

Where exactly is your data "@.DesktopData" stored in the database? Do you
have a field already defined?

Cheers,

Gord

"John Oakes" <john@.nospam.networkproductions.net> wrote in message
news:OwaYP%23KTEHA.1416@.TK2MSFTNGP12.phx.gbl...
Yeah, this is the basics (DT is just an object I'm taking from session and
serializing):

Dim ms As New MemoryStream
ms = SerializeDT(CType(Session("DT"), DTProcess))
Dim da() As Byte
da = ms.ToArray
cmd.Parameters("@.DesktopData").Value = da
SqlConnection1.Open()
cmd.ExecuteNonQuery()
SqlConnection1.Close()

Public Shared Function SerializeDT(ByVal DTSource As DTProcess) As
MemoryStream
Dim ms As New MemoryStream
Dim formatter As New BinaryFormatter
formatter.Serialize(ms, DTSource)
ms.Position = 0
Return ms
End Function

-John Oakes

"Gordz" <joeblow@.aol.com> wrote in message
news:10c96ar3sr73f4@.corp.supernews.com...
> I've been experiencing problems on some computers with XML Serialization.
On
> some computers the files do not get created on the web server's hard drive
> and it's been driving me nuts trying to figure it out.
> I store navigation history and application state in object collections and
> save this upon application exit by doing an XML.Serialize.
> I'd like to serialize directly to SQL Server instead. Can I create a
stream
> object to be used by SQL Server with serialization?
> Thanks
Yes, I have a field defined. The datatype is image, which is
variable-length binary data from 0 through 231-1 (2,147,483,647) bytes.

-John Oakes

"Gordz" <joeblow@.aol.com> wrote in message
news:10c9fasr23jm702@.corp.supernews.com...
> thanks John.
> I've never used binary objects in SQL before.
> Where exactly is your data "@.DesktopData" stored in the database? Do you
> have a field already defined?
> Cheers,
> Gord
> "John Oakes" <john@.nospam.networkproductions.net> wrote in message
> news:OwaYP%23KTEHA.1416@.TK2MSFTNGP12.phx.gbl...
> Yeah, this is the basics (DT is just an object I'm taking from session and
> serializing):
> Dim ms As New MemoryStream
> ms = SerializeDT(CType(Session("DT"), DTProcess))
> Dim da() As Byte
> da = ms.ToArray
> cmd.Parameters("@.DesktopData").Value = da
> SqlConnection1.Open()
> cmd.ExecuteNonQuery()
> SqlConnection1.Close()
> Public Shared Function SerializeDT(ByVal DTSource As DTProcess) As
> MemoryStream
> Dim ms As New MemoryStream
> Dim formatter As New BinaryFormatter
> formatter.Serialize(ms, DTSource)
> ms.Position = 0
> Return ms
> End Function
> -John Oakes
>
> "Gordz" <joeblow@.aol.com> wrote in message
> news:10c96ar3sr73f4@.corp.supernews.com...
> > I've been experiencing problems on some computers with XML
Serialization.
> On
> > some computers the files do not get created on the web server's hard
drive
> > and it's been driving me nuts trying to figure it out.
> > I store navigation history and application state in object collections
and
> > save this upon application exit by doing an XML.Serialize.
> > I'd like to serialize directly to SQL Server instead. Can I create a
> stream
> > object to be used by SQL Server with serialization?
> > Thanks

Serialize/Send a recordset content through network

Hi, the scenario should be like this:
I have a "Server" application, and a UserControl running on an asp.net page.
The UserControl sends a SQL Query string via UDP to the Server (after some
sort of authentication, etc etc)
The Server Application executes the query on his local SQL2k server
The Server Application gets the recordset returned by query execution
Then the server application sends to the UserControl the recordset returned
by the query execution
Could this be done? Like using a sort of Serialization of the SQLDataReader?
Or should i use another tecnique?
My target is to avoid opening the SQLServer directly to the public internet,
but to redirect all the queryes to my application, using some sort of
authentication and encryption.
I'm nearly new to .net framework so i'm discovering new things every day.
Thanx a lot for the help, and for any link that will be useful
MarcoMarco:
The scenario you describe sounds very much like a case where you would use a
web service. Since web services already use XML and SOAP, you will have the
serialization in the format you require.
David Lloyd
MCSD .NET
http://LemingtonConsulting.com
This response is supplied "as is" without any representations or warranties.
"M. Simioni" <m.simioniREMOVETHIS@.TOCONTACTMEwooow.it> wrote in message
news:1RRee.7789$TR5.6704@.news.edisontel.com...
> Hi, the scenario should be like this:
> I have a "Server" application, and a UserControl running on an asp.net
page.
> The UserControl sends a SQL Query string via UDP to the Server (after some
> sort of authentication, etc etc)
> The Server Application executes the query on his local SQL2k server
> The Server Application gets the recordset returned by query execution
> Then the server application sends to the UserControl the recordset
returned
> by the query execution
> Could this be done? Like using a sort of Serialization of the
SQLDataReader?
> Or should i use another tecnique?
> My target is to avoid opening the SQLServer directly to the public
internet,
> but to redirect all the queryes to my application, using some sort of
> authentication and encryption.
> I'm nearly new to .net framework so i'm discovering new things every day.
> Thanx a lot for the help, and for any link that will be useful
> Marco
>
Well, i forgot to mention, but i also need to fire events from the server
application to the user control.
The goal of the server application isn't only to be a 'forwarder' of sql
query commands from clients to db, but also should fire events to client
when something happens (like packets received from the rs232 located on the
server).
I planned to use an exchange of UDP message between the 'server application'
and the user control to exchange events (from srvr -> client) and sql
queryes (from client->srvr). But i couldn't realize how to exchange sql
resulting recordsets.
Can i do this with web services too? or should i split the two tasks in
a) a server application that send udp messages to 'clients'
b) a web service that the 'clients' use to query the database
sorry for my bad english :)
Marco
"David Lloyd" <info@.LemingtonConsulting.com> ha scritto nel messaggio
news:ZNSee.3282$0i3.1968@.bignews3.bellsouth.net...
> Marco:
> The scenario you describe sounds very much like a case where you would use
> a
> web service. Since web services already use XML and SOAP, you will have
> the
> serialization in the format you require.
>
> --
> David Lloyd
> MCSD .NET
> http://LemingtonConsulting.com
> This response is supplied "as is" without any representations or
> warranties.
>
> "M. Simioni" <m.simioniREMOVETHIS@.TOCONTACTMEwooow.it> wrote in message
> news:1RRee.7789$TR5.6704@.news.edisontel.com...
> page.
> returned
> SQLDataReader?
> internet,
>
Marco,
You never can sent something to a client. Therefore is to much protected.
You can communicate with a client when he has on the other side a program
that accept what you sent.
I think as well that the suggestion from David can maybe be a good solution
for you. We can never see from this newsgroup if it real fits. Have a look
at this pages.
http://msdn.microsoft.com/library/d...r />
hrough.asp
I expect however as well, that trying to reach your goall with a recordset
can be much harder than using the ADONET components.
I hope this helps,
Cor