As we have already discussed at the beginning of this
article, SQL Server Session management requires the Serialization and
De-Serialization process to store the session values in the Database. And this
requirement becomes more prominent when we will try to dump an object directly
to the Session. Because the integers, strings, etc. can be directly
stored/retrieved to and from the Session (as it goes through the internal
conversion actually), for objects we need to do the process by our own.
For that we need to exploit the Serialization and
De-Serialization process. Let us see the example doing the same below.
Listing 4
Dim oDataDescription As New DataDescription(0, "ZERO")
'Serializes the oDataDescription object and stores the serialized data in Session
Session.Add("test", SerializeData(oDataDescription))
'De-serializes the Data from the Session
'and brings the object into its original shape.
oDataDescription = DeSerializeData(Session.Item("test"))
Response.Write("Data: " & oDataDescription.Data & "<br>")
Response.Write("Description: " & oDataDescription.Description)