BinaryFormatter in ADO.NET 2.0

Published Sun, Jan 23 2005 22:26 | William

This is hardly hot off of the press, but I had a few questions about it and figured I'd post it.  There is a new RemotingFormat property w/ DataSets in ADO.NET 2.0 - and depending on how you are trying to work things, the differences can be profound.  Note that when I use 10 records, the XML version is 1kb whereas the Binary is 7kb - but my how quickly seasons change.....

SqlConnection cn = new SqlConnection("Server=PimpDaddyServer;Integrated Security=True;Database=AThaWayThug");

SqlCommand cmd = new SqlCommand("SELECT PimpID, PimpName FROM Thugs WHERE PimpID < 1000", cn);

SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet("Pimpin");

da.Fill(ds, "AintEasy");

ds.WriteXml(@"C:\sizetest.xml"); //94kb @1,000  - 955kb @10,000

ds.RemotingFormat = SerializationFormat.Binary;

IFormatter Formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

Stream myStream = new FileStream(@"C:\sizetest.bin", FileMode.Create);

Formatter.Serialize(myStream, ds); //24kb @1,000 - 196kb @10,000


Comments

# William said on January 23, 2005 11:07 PM:

Yeah and the performance is about 10's of times better too !!

Now here's the catch - and I know this is do-able.

Write a formatter that will let you deserialize a binaryformatted dataset from .NET 2.0, to a .NET 1.1 environment.

I know this is do-able, and I know this'll have a profound impact in 1.1 applications (Imagine all those people who remote datasets, but just can't make the big 1.1 to 2.0 change just yet).

That'd be the shit !!

I'd do it, but I'm so damn tied up right now !! But I just might do it.

# William said on January 24, 2005 7:51 AM:

... you mean XML is less efficient? Heretic! .NET is Microsoft's platform for XML. Didn't you know that all data is stored as native XML in Yukon? <g>

# William said on January 24, 2005 8:08 AM:

Actually, I realized that saying anything to the effect of "XML is great but there are a few of life's problems like Nuclear Proliferation, AIDS and Cold weather that it's not particularly good at solving" would be heresy. Not only that, we all know that no matter how lame your stuff is, if you provide XML support for it, bugs magically disappear and it automatically becomes cooll

To be fair, it appears that if you have virtually no data, the binary is a little more bloated, so if you are dealing with DataSets with < 1 record, XML is definitley the way to go across the board - but at the 1+ level, then binary quickly shows it's superiority in this regard.

But keep it between us - I remember what they tried to do to Gallileo and I'm not nearly as cool as he is so I'd be a dead man.

# William said on January 24, 2005 8:09 AM:

Dammit Sahil - that's precisely the type of challenge that I could really get caught up in for a night or two - going to have to think about that b/c it would kick a33 to do it.

# William said on January 25, 2005 4:33 PM:

On GDN there is some code to do binary serialization in 1.1 (I realize that it is not exactly what Sahil is asking for, but it may be of interest anyway).

http://weblogs.asp.net/jackieg/archive/2004/12/16/319469.aspx

Search

This Blog

Tags

Community

Archives

News

My other sites

Cool Stuff

Book Stuff

Security

ORM

Data Access

Funny Stuff

Compact Framework Stuff

Web Casts

My KnowledgeBase Articles

My MVP Profile

Design Patterns

Performance

Debugging

Remoting

My Fellow Authors

My Books

LINQ

Misc

Speech

Syndication

Email Notifications