Using BinaryFormatter to serialize the class into a MemoryStream and Saving to Remote SQL Server Database

Posted on 2006-05-24
Last Modified: 2012-08-14
Can some one tell me how to do the following use the BinaryFormatter to serialize a Business Object into a MemoryStream and save it to a column in  a SQL Server database on a remote server. Then have a method that retrieves the column, deserializes it (again using the BinaryFormatter class) and rehydrates it into a new instance of the business obeject. The actucal insert, delete should be done using a stored procedure.
Question by:MelvinTucker
    1 Comment
    LVL 37

    Accepted Solution

    Doing an insert/delete for the data is no different than any other data .. it would just be varchar field (then base64 your serialized data).

    As for serializing the object.

    MemoryStream s = new MemoryStream();
    BinaryFormatter Formatter = new BinaryFormatter();
    Formatter.Serialize(s, object);
    then you can access the bytes (for conversion with s.ToArray()) .. You can use Convert.ToBase64 and Convert.FromBase64 to convert back and forth between base64.


    Greg Young

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now