Quick response somebody

  • Thread starter Thread starter Marinos Christoforou
  • Start date Start date
M

Marinos Christoforou

I have an application which is multi-tiered. I want to return a
sqldatareader object from a function called in the data access tier. I know
that the preferred way of transferring data through tiers is with a dataset
but I want to use a datareader. My question is it possible to do this given
that the datareader object must remain connected to the database, so how
would I code the data access component correctly.

My first attempt failed because my code called the close method of the
sqlconnection object before returning the datareader abject.

However return the datreader from the data access layer without closing the
conncetion doesn't seem right.
 
However return the datreader from the data access layer without
closing the conncetion doesn't seem right.

In the moment you close your connection you loose your datareader...

But your application design seems to be totaly screwed...
Just imagine what would happen if you'Re working with services Components
in a WebFarm...

It would be possible to pass a datareader, although you will need more than
one functions calls and you will have to call them in a specific order. All
in all this would be such a bad solution design that I can'T even tell you
how to do it ;-)

But if you really, really need it:

Create a Method that passes the datareader
Create a Method that initializes the datareader
Create a Method that cleans ip the datareader

Beware of multi-machine situations, and different user credentials etc..
'coz this would make the reader fail.

--
------ooo---OOO---ooo------

Peter Koen - www.kema.at
MCAD MCDBA MCT
CAI/RS CASE/RS IAT

------ooo---OOO---ooo------
 
Design issues aside you can also do the following which will close the
connection when the datareader is closed
assuming sqlCMD is a SqlCommand object

sqlCMD.ExecuteReader(System.Data.CommandBehavior.CloseConnection);

Chris Torgerson
 
Thanks Peter,

Given the design issues, I would like to ask the following.

A dataReader is supposed to be fastest way to retrieve data espcially in
read-only data environments.

Applications are supposed to be multi-tiered, broken into layers that
handle the UI/Business/Data etc.

So how do you combine the two?

I suppose one way is to not return the DataReader object as such, but
instead the data in an array or list or another suitable container?

I am trying to feel my way into this area.
 
Back
Top