?
Solved

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

Posted on 2006-05-24
3
Medium Priority
?
425 Views
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.
0
Comment
Question by:MelvinTucker
1 Comment
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 1000 total points
ID: 16756986
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.

Cheers,

Greg Young
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Loops Section Overview
Suggested Courses

840 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