IDisposable and SqlDataReader

  • Thread starter Thread starter Doug Holland
  • Start date Start date
D

Doug Holland

The Dispose() method of SqlConnection will automatically
close the connection if it is open, but the Dispose()
method of SqlDataReader doesn't appear to close the
reader, is this by design?

using(SqlConnection _connection = new SqlConnection())
{
} // SqlConnection closed by SqlConnection.Dispose()

using(SqlDataReader _reader = returnsReader())
{
} // SqlDataReader NOT closed by SqlDataReader.Dispose()
 
How are you verifying that the reader is not being closed? I just
double-checked in the code to make sure, and Dispose() just calls Close().

--
Pablo Castro
Program Manager - ADO.NET Team
Microsoft Corp.

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Pablo,

Thanks for the quick response ... unfortunately I just
noticed a fault in my test code, sorry about that!!!

Doh!!! (Don't you hate it when that happens)

Doug
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top