[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.caching

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

Daniel

9/18/2007 9:15:00 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


2 Answers

sloan

10/26/2007 6:23:00 PM

0



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@yahoo.com> wrote in message
news:OXdwsjj%23HHA.464@TK2MSFTNGP02.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
>


Alvin Bruney [MVP]

10/27/2007 1:41:00 AM

0

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@ipass.net> wrote in message
news:OrW8A1$FIHA.3376@TK2MSFTNGP03.phx.gbl...
>
>
> 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@yahoo.com> wrote in message
> news:OXdwsjj%23HHA.464@TK2MSFTNGP02.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
>>
>
>