Back to VSLive! San Francisco Show Daily Home
3 Tips for DataSets and Transactions
Learn how to create a helper function that can fill both untyped and typed DataSets, and more.
by Jimmy Nilsson
VSLive! San Francisco, February 12, 2003
Note: Jimmy Nilsson is presenting "Data Containers for .NET" at VBITS San Francisco, Wednesday, February 12, and "In-Depth Transaction Design" on Thursday, February 13. These tips are from those sessions.
Binary Serialization of DataSets Isn't Very Effective
Despite what I think Microsoft says in a recent architecture paper, "Application Architecture for .NET: Designing Applications and Services," custom classes and collections might be much more efficient than DataSets. One example of that is when you need to send data over a remoting boundary with binary serialization.
Assume you need to send some orders in a data container. If you choose a DataSet as the data container, it willaccording to my teststake approximately three times as long as if you had used a custom order collection as the data container. And that is end to end, meaning it includes the time to fetch the order from the database and the time to inspect each value in the order at the consumer side.
The biggest reason for this is probably that the DataSet is serialized as XML even when a binary formatter is used, so the DataSet will be approximately five times as large as the custom collection over the wire. See for yourself by using this code on a DataSet:
Dim fs As IO.FileStream = New _
IO.FileStream("c:\temp\ds.txt", _
IO.FileMode.Create)
Dim bf As New System.Runtime.Serialization. _
Formatters.Binary.BinaryFormatter _
(Nothing, New _
Runtime.Serialization.StreamingContext _
(Runtime.Serialization. _
StreamingContextStates.Remoting))
bf.Serialize(fs, anOrderDS)
fs.Close()
The code will serialize the DataSet with a binary formatter and write it to a file.
Then open the file in Notepad. When you know about this problem and you can't live with it, you can choose a workaround such as wrapping the DataSet and writing a custom serialization implementation. You could, of course, also choose another data container if you don't see a big advantage in the built-in functionality of the DataSet.
Back to top
|