is a reader automaticaly disposed if the connection it is associated with is closed?

  • Thread starter Thread starter Daniel
  • Start date Start date
D

Daniel

is a reader automaticaly disposed if the connection it is associated with is
closed?

what will happen if an app:

while true
open connection
open reader
close connection
end while
 
A DataReader can no longer be accessed once the connection is closed.
However, you don't declare a DataReader as a "New" instance like a
Connection or DataTable object. What's the concern here? The DataReader is
simply a pipe to the resultsets returned by the Command instance.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant, Dad, Grandpa
Microsoft MVP
INETA Speaker
www.betav.com
www.betav.com/blog/billva
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
 
Daniel said:
is a reader automaticaly disposed if the connection it is associated
with is closed?

what will happen if an app:

while true
open connection
open reader
close connection
end while

Depends on the ADO.NET provider. In ODP.NET for example, it's not
disposed. So you have to call Dispose on the Datareader object (and
also the command and parameter! objects) yourself to be sure you won't
get memory leaking away.

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
 
Back
Top