↑ Grab this Headline Animator

Monday, January 26, 2009

Why is DataSet slower than DataReader ?

Following are the major differences between “DataSet” and “DataReader” :-
  •  “DataSet” is a disconnected architecture, while “DataReader” has live connection while reading data. If we want to cache data and pass to a different tier “DataSet” forms the best choice and it has decent XML support.
  •  When application needs to access data from more than one table “DataSet” forms the best choice.
  • If we need to move back while reading records, “datareader” does not support this functionality.
  • But one of the biggest drawbacks of DataSet is speed. As “DataSet” carry considerable overhead because of relations, multiple tables etc speed is slower than “DataReader”. Always try to use “DataReader” wherever possible, as it’s meant specially for speed performance.

Submit this story to DotNetKicks


Portablenut said...

If you need the data disconnected, what's preferable between a dataset or iterating through the datareader and mapping data to classes and insert to an array?

Anonymous said...

Hi Portablenut...

TDataReader has the least amount of overhead, and is faster.
It also has some issues which DataSet and DataTable do not, such as being
read-only, forward-only, and necessitating that a Connection remain opened
dring its entire lifetime. DataSets and DataTables are disconnected Record
Sets. The DataSet is also implicitly serializable as XML. With dataset u can perform certain operations like filtering, editing, sorting...

If we are using DataReader we should not forget to use command behaviour.CloseConnection attribute to close connection attached to DataReader when we close it. (important when u r transfering reader to other layer where u can't get connection object to close it)

or best thing is to use Using Statement (If possible).

Post a Comment

Post your comments/questions/feedback for this Article.


Latest Articles