HighTechTalks DotNet Forums  

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

ASP.net Caching microsoft.public.dotnet.framework.aspnet.caching


Discuss is a reader automaticaly disposed if the connection it is associated with is closed? in the ASP.net Caching forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Daniel
 
Posts: n/a

Default is a reader automaticaly disposed if the connection it is associated with is closed? - 09-18-2007 , 04:14 PM






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



Reply With Quote
  #2  
Old   
sloan
 
Posts: n/a

Default Re: is a reader automaticaly disposed if the connection it is associated with is closed? - 10-26-2007 , 01:23 PM








Why don't you try it and see?


This willl get you started. Then post your results.



public IDataReader CustomersGetAllReader()
{

String myConn ="Provider=Microsoft.JET.OLEDB.4.0;Data
Source=C:\\Wutemp\\Nwind.mdb;"; //naturally, you gotta have a database (mdb)
somewhere...change value here
String myQuery = "Select [CustomerID],[ContactName],[City] From
[Customers];";

OleDbConnection cn = new OleDbConnection(myConn);
cn.Open();
OleDbCommand cmd = new OleDbCommand(myQuery , cn);

return cmd.ExecuteReader(CommandBehavior.CloseConnection ); //


}



"Daniel" <softwareengineer98037 (AT) yahoo (DOT) com> wrote

Quote:
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




Reply With Quote
  #3  
Old   
Alvin Bruney [MVP]
 
Posts: n/a

Default Re: is a reader automaticaly disposed if the connection it is associated with is closed? - 10-26-2007 , 08:41 PM



No it is not disposed off. In the default case, it is flagged as closed and
sent back to the connection pool. If pooling is disabled, an unusual case,
and no more connections are open with an exact connection string match, the
resource becomes eligible for garbage collection at which point, the dispose
method on the resource will be called.

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless Author Plug
OWC Black Book 2nd Edition
Exclusively on www.lulu.com/owc
$24.99


"sloan" <sloan (AT) ipass (DOT) net> wrote

Quote:

Why don't you try it and see?


This willl get you started. Then post your results.



public IDataReader CustomersGetAllReader()
{

String myConn ="Provider=Microsoft.JET.OLEDB.4.0;Data
Source=C:\\Wutemp\\Nwind.mdb;"; //naturally, you gotta have a database
(mdb) somewhere...change value here
String myQuery = "Select [CustomerID],[ContactName],[City] From
[Customers];";

OleDbConnection cn = new OleDbConnection(myConn);
cn.Open();
OleDbCommand cmd = new OleDbCommand(myQuery , cn);

return cmd.ExecuteReader(CommandBehavior.CloseConnection ); //


}



"Daniel" <softwareengineer98037 (AT) yahoo (DOT) com> wrote in message
news:OXdwsjj%23HHA.464 (AT) TK2MSFTNGP02 (DOT) phx.gbl...
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






Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.