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
 
Back
Top