.NETGURU
DataSet-Class Vs DataReader-Class
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngspeed' list.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

Adnan Qamar
Can someone tell me in an overloaded environment, should DataReader class be
used instead of DataSet class to access the database server?
Reply to this message...
 
    
Alban Schmid
Can someone tell me in an overloaded environment, should DataReader class be
used instead of DataSet class to access the database server?
Reply to this message...
 
    
Bill Swartz
Can someone tell me in an overloaded environment, should DataReader class be
used instead of DataSet class to access the database server?
Reply to this message...
 
    
Scott Worley
<html><div style='background-color:'><DIV>
<P>Hi Adnan,</P>
<P>Depends on your usage of the class to be honest, as always it goes down to performance, and which is the better, you can use the brief list below as a guide:</P>
<P>Use a dataset for complex data relationships, and cache it or its dataviews and copy those into you class fields/collections, remember cached data works is a lot faster to access than when it is stored on a database server. (you can also use a cached dataview, and loop through it to populate, your class fields and collections, again with great speed)</P>
<P>Use a datareader to load you class fields/collections, when the datasource is used less frequently, and would not benifit from caching. </P>
<P>Thats it, if you have more queries on these technique please ask.</P>
<P> </P>
<P>Scott Worley, <A href="http://lw3fd.law3.hotmail.msn.com/cgi-bin/compose?mailto=1&;msg=MSG1014986993.16&start=2021150&len=6581&src=&type=x&to=worleys%40project%2dinspiration%2ecom&cc=&bcc=&subject=&body=&curmbox=F000000001&a=f9dc3e478e7578bda7911679687d86cf"><FONT color=#000099>Click here to reveal e-mail address</FONT></A></P>
<P>    Author of: Inside ASP.NET, New Riders Publishing, Nov 2001.</P>
<P>    Working on: Commerce Server 2002 and .NET Unleashed, SAMS<BR><BR></P></DIV>
<DIV></DIV>
<P><BR></P></div><br clear=all><hr>Get your FREE download of MSN Explorer at <a href='http://g.msn.com/1HM105301/12'>http://explorer.msn.com</a>.<br></html>

Reply to this message...
 
    
Sten Sundblad
Can someone tell me in an overloaded environment, should DataReader
class be
used instead of DataSet class to access the database server?
Reply to this message...
 
    
Bill Swartz
Can someone tell me in an overloaded environment, should DataReader
class be
used instead of DataSet class to access the database server?
Reply to this message...
 
    
Steven A Smith (VIP)
Can someone tell me in an overloaded environment, should DataReader
class be
used instead of DataSet class to access the database server?
Reply to this message...
 
    
Bill Swartz
Can someone tell me in an overloaded environment, should DataReader
class be
used instead of DataSet class to access the database server?
Reply to this message...
 
    
Sten Sundblad
Can someone tell me in an overloaded environment, should DataReader
class be
used instead of DataSet class to access the database server?
Reply to this message...
 
    
Sten Sundblad
Can someone tell me in an overloaded environment, should DataReader
class be
used instead of DataSet class to access the database server?
Reply to this message...
 
    
Sten Sundblad
Can someone tell me in an overloaded environment, should DataReader
class be
used instead of DataSet class to access the database server?
Reply to this message...
 
    
Varadhg
As I see you guys went quite far to test everything for performance..

but, can you explain or give example of a client and server process in the
Asp.Net Environment...??

1. All our Web Controls are made runat=server.
2. I'm using a seperate DB Components Class.
3. Create an Instance of the DB Component Class from the Codebehind, and get
the DataSet.
3. In the component class use SqlDataReader to fetch all the data, convert
them into Dataset (and cache them in some cases) and return DS.
4. either (cache or not) this Dataset and use it to bind web
control(populate data).
5. and the html results will be pushed to the Client ?? (by asp.net process
!!)

Now, how do I find out where I cross Process Boundry ??

Thanks,

Gopinath

"Sten Sundblad" <Click here to reveal e-mail address> wrote in message news:607608@aspngspeed...

If you create the datareader in one process (the server process) and
consume it in another (the client process), each time you access the
datareader you do it through a proxy in the client process that
represents the datareader. The proxy talks to a stub in the server
process, the stub representing the client. For a non-trivial set of
data, which requires a non-trivial number of data access operations,
this cross-process communication really hearts your performance.

The dataset, on the other hand, is designed to marshall by value rather
than by reference. This means that the content of the dataset is
serialized and then copied to the client process, where the dataset is
built up again from the serialized copy. All the access of the dataset
is then in-process and still as fast as when everything ran in the same
process.

So, with the dataset you pay the cross-process price once; with the
datareader you pay it once for each access. This is what makes the
difference so large. In my opinion it's very important to bear this in
mind when you design your data access operations. If you're dead sure
you'll never going to use the data carrier out-of-process, you can make
a small performance gain by using a datareader rather than a dataset. If
you're wrong and have to use it cross-process, the performance price
you'll have to pay can be very high.

See more on this in my answer to Steven A. Smith!

Best
/Sten

--------------------------------------------------------------------
Sten Sundblad, ADB-Arkitektur AB
Microsoft Regional Director, Sweden
Email: Click here to reveal e-mail address
WWW: http://www.adbark.se http://www.adbark.com
Kungsgatan 113, Box 437, 751 06 UPPSALA, SWEDEN
Phone: +46(0)18-69 51 00 Fax: +46(0)18-69 51 59

Reply to this message...
 
    
Sten Sundblad
Varadhg,
In your example, as I understand it, you don't. I.e., not until you call
the database from the DB Component Class, at least if it's a proper
database product such as SQL Server or Oracle.

But let's say that during the next year or so you upgrade your database
to the next version of SQL Server (codename Yukon). Also assume that you
want to take advantage of the opportunity in Yukon to install the
assembly that contains your DB Component Classes as stored procedures;
then these objects would run in Yukon's process rather than in the IIS
process. Then you would cross a process boundary between the code behind
object and the DB access object, in most cases also a machine boundary
which in principle is the same but performance-wise more expensive.

Anyway, you'd be OK because you already transport the data in a dataset
rather than sending back a reference to a data reader.

Hope this clarifies my intentions.

Best
/Sten

--------------------------------------------------------------------
Sten Sundblad, ADB-Arkitektur AB
Microsoft Regional Director, Sweden
Email: Click here to reveal e-mail address
WWW: http://www.adbark.se http://www.adbark.com
Kungsgatan 113, Box 437, 751 06 UPPSALA, SWEDEN
Phone: +46(0)18-69 51 00 Fax: +46(0)18-69 51 59

-----Original Message-----
From: Varadhg [mailto:Click here to reveal e-mail address]
Sent: den 5 mars 2002 20:13
To: aspngspeed
Subject: [aspngspeed] Re: DataSet-Class Vs DataReader-Class

As I see you guys went quite far to test everything for performance..

but, can you explain or give example of a client and server process in
the
Asp.Net Environment...??

1. All our Web Controls are made runat=3Dserver.
2. I'm using a seperate DB Components Class.
3. Create an Instance of the DB Component Class from the Codebehind, and
get
the DataSet.
3. In the component class use SqlDataReader to fetch all the data,
convert
them into Dataset (and cache them in some cases) and return DS.
4. either (cache or not) this Dataset and use it to bind web
control(populate data).
5. and the html results will be pushed to the Client ?? (by asp.net
process
!!)

Now, how do I find out where I cross Process Boundry ??

Thanks,

Gopinath

"Sten Sundblad" <Click here to reveal e-mail address> wrote in message
news:607608@aspngspeed...

If you create the datareader in one process (the server process) and
consume it in another (the client process), each time you access the
datareader you do it through a proxy in the client process that
represents the datareader. The proxy talks to a stub in the server
process, the stub representing the client. For a non-trivial set of
data, which requires a non-trivial number of data access operations,
this cross-process communication really hearts your performance.

The dataset, on the other hand, is designed to marshall by value rather
than by reference. This means that the content of the dataset is
serialized and then copied to the client process, where the dataset is
built up again from the serialized copy. All the access of the dataset
is then in-process and still as fast as when everything ran in the same
process.

So, with the dataset you pay the cross-process price once; with the
datareader you pay it once for each access. This is what makes the
difference so large. In my opinion it's very important to bear this in
mind when you design your data access operations. If you're dead sure
you'll never going to use the data carrier out-of-process, you can make
a small performance gain by using a datareader rather than a dataset. If
you're wrong and have to use it cross-process, the performance price
you'll have to pay can be very high.

See more on this in my answer to Steven A. Smith!

Best
/Sten

--------------------------------------------------------------------
Sten Sundblad, ADB-Arkitektur AB
Microsoft Regional Director, Sweden
Email: Click here to reveal e-mail address
WWW: http://www.adbark.se http://www.adbark.com
Kungsgatan 113, Box 437, 751 06 UPPSALA, SWEDEN
Phone: +46(0)18-69 51 00 Fax: +46(0)18-69 51 59

| [aspngspeed] member Click here to reveal e-mail address =3D YOUR ID
| http://www.asplists.com/asplists/aspngspeed.asp =3D JOIN/QUIT
| http://www.asplists.com/search =3D SEARCH Archives

Reply to this message...
 
 
System.Data.DataSet
System.Data.SqlClient.SqlDataReader
System.Environment




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification