Here are two comparisons and from what I've seen, pretty much tell the
story. The first on focuses on the DataReader vs DataTable exclusively,
http://www.devx.com/vb2themax/Article/19887/0/page/2 The next compares all
data access strategies
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/bdadotnetarch031.asp
Darin, I say this with all due respect and if I sound condescending please
be assured that nothing could be further from my intent. However, choosing
a data access strategy is a big deal that on any nontrivial app will have
serious ramificiations for many people. Like Cor mentioned, two strategies
are avaiable (at least two) and both have intended uses. Moreover, many
things will perform well in test, and then as things grow, may not scale all
that well.
There are a lot of considerations in this regard and writing off a whole
aspect of methodology is not well advised. To write it off for a reason
like 'you don't want developers to forget to close connections' is
horrifying. The whole presupposition of your question, and oversimplifies
this to a point that it's irresponsible. I'm not saying you are
irresponsible and I know my tone probably seems like I'm lecturing. I'm
not. I just want to point out that making a design decision on something
like this is a recipe for disaster and I don't want to see anyone make this
mistake. I think taking a step back and understanding the whole ADO.NET
paradigm and its architecture would be very beneficial. Check out David
Sceppa's ADO.NET core reference or Bill Vaughn's ADO and ADO.NET Best
practices. Both books explain in detail the many issues that you will
confront. Trust me, it's a lot more involved than developers forgetting to
close open connections. Even if this was a good reason, it'd be easy enough
to work around but that's another story.
Performance isn't the only issue, nor is simplicity. These issues are
seldom black and white and usually involve tradeoffs. If you check out any
of my Efficiently Using ADO.NET xxxx articles at
www.knowdotnet.com in the
DataAcess section, I bring up many of these tradeoffs. What works great in
one scenario is often terrible in another and scalablity is a HUGE issue.
Design that ignores this is relying on the hope that change won't happen for
its success. This is ill advised.
I answered the technical aspect of your question with those first two links
but trust me, this isnt' an either or question. You are choosing between a
connected and a disconnected strategy and neither is 'good' across the board
in every situation.
There are many other performance tweak, like connection pooling, query
structure, index strategy table design etc tht will have huge performance
implications, far beyond what object you use to access the data.
The main thing is using the right tool for the right job and employing a
strategy that will bend as needs change.
I'll be glad to elaborate on any of this, so feel free to take me up on the
offer. I'm sure on this one, just about everyone else here will agree with
me on this and would be willing to offer their opinions too.
Whatever you do though, please make your decision on factors more
substantial than the ones mentioned though. Please do yourself a favor and
look into it a lot more - same for your developers. If this is the best
counter point they'd make to such a suggestion, they probably need to either
learn a lot more about ADO.NET, or if they know better reasons and just
didn't mention them, need to speak up more.
Again, I apologize if it sounds like I'm preaching, I've just seen two
projects blow up when I first started over this precise issue (thank God I
don't work there any more) and I can't imagine a scenario where it wouldn't
repeat itslef.
You can opt to not use DataReaders for many reasons, but even datatables use
DataReader behind the scenes as do the command's .Executexxx methods so you
can't swear off connected methodology without forgoing a fair amount. In
some projects this might be safe, but in most it's ill advised. Either way
, making an informed decisioin is the important thing.
Let me know if you have any questions.
Bill
--
W.G. Ryan MVP Windows - Embedded
www.devbuzz.com
www.knowdotnet.com
http://www.msmvps.com/williamryan/
Darin said:
I would like to use the datatable instead of the datareader so I do not
have to worry about developers forgetting to close the datareader to ensure
the connection gets closed (using
System.Data.CommandBehavior.CloseConnection). But as soon as I say we will
only use the datatable then everyone will talk about the speed difference.
Can someone point me to documentation showing the speed difference between
the two? Is there much of a difference? Is there a persuasive argument to
using datatables instead of datareaders?