Cleaning up after using an OleDbDataReader
Posted on 2006-07-18
I have just been made aware that I need to call Dispose() when using an OleDbCommand. I now do this in the "finally" block of the code to make sure it gets called when an exception is thrown. But what about an OleDbDataReader?
Is this code appropriate?
OleDbDataReader driverRuns = dbSelectCommand1.ExecuteReader();
If there is an exception in ExecuteReader(), does the Close() need to be called? I assume it's null anyway. Then what about explicitly setting the OleDbDataReader to null? This would be something I would also put into the finally block.
driverRuns = null;