SqlDataReader

  • Thread starter Thread starter Tom
  • Start date Start date
T

Tom

Hello Friends,
Why SqlDataReader is not inherited from
System.ComponentModel.Component?
While every other major class (SqlCommand, SqlConnection,
SqlDataAdapter) from SqlClient namespace is inherited from
System.ComponentModel.Component and supports IComponent
interface.

IComponent enables object-sharing between applications,
while MarshalByRefObject Class (which SqlDataReader
inherits) enables access to objects across application
domain boundaries in applications that support remoting.

Does it means that one can not use SqlDataReader between
applications if they don't support "remoting"?
Can anybody from microsoft explain impact of this design?
And why they select such class hierarchy?
Regards
Tom
 
To take the point of absurdity, imagine an Enterprise level app with a
couple of app servers and a database server. Your web server creates a
connection object that gets passed across many machines until it fills a
data reader. Now, this connection has to be marshalled all the way back, so
it can be closed. A round trip from web app to database and back takes a
couple of seconds.

Now, compare to a DataReader that is not marshalled. Is it less or more
expensive to repackage the data from the Reader or to hold up the Connection
object as it is marshalled back across the tiers.

Also, compare a DataSet, which is designed to be passed sans connection, as
XML.

The point is that a Reader requires the connection is open from the time the
first record in the stream is filled until you are finished with it. This
means you have to marshall all of the baggage along with the reader so you
can properly close and dispose of the connection when you are finished with
the data in the Reader. Admitedly, my example may be a bit too heavy, but
since it becomes possible as soon as you open Pandora's box, do you want to
open the box so a few people with no intention of multiple tiers on multiple
machines might "potentially" reap a small benefit?

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
 
Back
Top