none
Streaming DataTables: Is BinaryFormatter safe? RRS feed

  • Question

  • I can't use XML for this application, but I'm concerned about possible data loss with the BinaryFormatter.

     

    Is there a data loss concern with the following code?  The DataTable being streamed has strings, decimals, ints, boolean, datetime and byte datatypes.

     

    MemoryStream mstream = new MemoryStream();

    BinaryFormatter formatter = new BinaryFormatter();

    formatter.Serialize(mstream, aDataTable);

    Byte[] bytes = mstream.ToArray();

    mstream.Close();

    //Write the byte array to a SQL table as varbinary

    //Read the varbinary field back from the SQL table into a byte array

    mstream = new MemoryStream(bytes);

    mstream.Read(bytes, 0, bytes.Length);

    formatter = new BinaryFormatter();

    aDataTable = (DataTable)formatter.Deserialize(mstream);

    mstream.Close();

     

     

    Thanks in advance.

    Bill

    Friday, January 18, 2008 12:28 AM