Serialization to DB

I want to serialize an object in VB.Net and store the data in SQL Server 2000, and be able to retrieve and deserialize it later.  Can anyone explain how I can do that   Specifically, how do I insert a stream into a database field   What data type should the field be   Image   This seems like it should be possible, but I'm having trouble finding info on how to do it.  Any help would be appreciated.  Thanks!

Answer this question

Serialization to DB

  • Saranya

    Depends on the formatter used, binary or SOAP, a [Serializable]object can be serialized into binary byte array or clear text Xml in SAOP style, either way can be save in file or database, then later used to deserialized to build an object with the same class definition, and initialize it with the state data. The byte array/xml data contains the class info and the object state data, the object state is the values of the fileds and properties.

    For example, DataSet is serializable, a DataSet object with some user data in it can be serialized, stored, then later create another DataSet object with the same structure and user data.

    Many .NET native classes are serializable. To serialize a custom class, that class has to be defined as [Serializable] in C#/<Serializable> in VB, this is simple attribute may be enough for simple classes, more complex classes may require explicitely implementation of the ISerializable interface, which has a constrctor for deserialization and a GetObjectData method for serialization.

    The IXmlSerializable interface, XmlSerializer class are for xml serialization.

    Serialization is useful primarily for transmitting data from one place to another, use it for data persistance may not be a good idea, at lease from performance, and code complexity consideration. When there is a database, better try to store each data item in a table column, a data record can be considered as an object state, and the table definition as the class structure.    

  • Phil333

    Serialize to a new MemoryStream, and save the result from "Convert.ToBase64String(MemoryStreamName.ToArray)" to a Text field in the database.

    To deserialze, you would load from "New MemoryStream(Convert.FromBase64String(TextFromDatabase))"

  • Duppi

    To do this the object needs to be "serialized".. How do I determine if it is

    I am trying to store MicroStation Element objects to database, but it seems they are not able to be serialized.. Does that mean that I can't store them in a database

    Havard



  • Paulo Sebastiao

    DB table can store binary, save the base64 conversion, fater this way, and save more space, because base64 takes 1/3 more space, it turns 3 bytes into 4 bytes.

    Base64 is necessary if the data is used in XML or HTML, ASP.NET __VIEWSTATE is base64 string. 


  • Serialization to DB