Re: closing DataReader in another layer
From: DS (nojunkmail.signups_at_rogers.com)
Date: 11/26/04
- Next message: avnrao: "Re: Icon in contextmenu.."
- Previous message: Shiva: "Re: Icon in contextmenu.."
- In reply to: Michael Giagnocavo [MVP]: "Re: closing DataReader in another layer"
- Next in thread: Nick Malik: "Re: closing DataReader in another layer"
- Reply: Nick Malik: "Re: closing DataReader in another layer"
- Reply: Michael Giagnocavo [MVP]: "Re: closing DataReader in another layer"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 26 Nov 2004 02:28:05 -0500
"Michael Giagnocavo [MVP]" <mggUNSPAM@atrevido.net> wrote in message
news:O9RNe$30EHA.3416@TK2MSFTNGP09.phx.gbl...
> Try this:
>
> theReader = theConnection.ExecuteReader(CommandBehavior.CloseConnection);
> return theReader;
>
> CommandBehaviour.CloseConnection makes the reader so that when the reader
> is closed, the underlying connection gets closed too. This allows you to
> call Close() on the reader somewhere else, and not leak a connection.
>
> However, you might consider DataSets for a different reason: They actually
> can go across physical layers, not just logical ones.
>
> --
> Michael Giagnocavo
> MVP
> www.atrevido.net
Thanks for the reply Michael,
I'd like to not even have to call the .Close on the reader in the business
tier as it is easy to forget to do, especially down the road. With a dataset
its not a big deal since I can close the connection in the DAL before the
dataset even gets returned and never have to worry about it in the buiness
layer. With a dataset if I forget to dispose it, at least that gets taken
care of by the garbage collection, whilst I believe a connection close does
not happen correctly on garbage collection of the DataReader.
Cheers,
Dan
- Next message: avnrao: "Re: Icon in contextmenu.."
- Previous message: Shiva: "Re: Icon in contextmenu.."
- In reply to: Michael Giagnocavo [MVP]: "Re: closing DataReader in another layer"
- Next in thread: Nick Malik: "Re: closing DataReader in another layer"
- Reply: Nick Malik: "Re: closing DataReader in another layer"
- Reply: Michael Giagnocavo [MVP]: "Re: closing DataReader in another layer"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|