This is the scenario:
That's gorgeous! Thanks for this memory saver. Besides Marc's fix I modified the constructor to open connection and dispose in case the open or execute fails to reduce code/exception handling in caller. (Didn't know Dispose could be called from constructor). Constructor mod:
try
{
this.command = command; // store for disposal
if (command.Connection.State != ConnectionState.Open)
command.Connection.Open();
dataReader = command.ExecuteReader(CommandBehavior.SequentialAccess);
dataReader.Read();
}
catch (Exception ex)
{
Dispose();
throw;
}