I understand that wrapping an IDbConnection object in a using block ensures that Dispose will get called and the resources it is using will get freed. That being said do I also need to wrap IDbCommand and IDataReader in using blocks as well, or is just wrapping the connection object sufficient. Thanks.
There are a number of easy ways to work out the answer to this for any given object without consulting the documentation:
using
block and it's not IDisposable
, you'll get a syntax error..Dispose
method (easily checked in Intellisense) then you should wrap it.IDisposable
(easily checked through "go to definition" or the new "peek" functionality in VS) you should wrap it.Alternatively, by way of example, you can see from the MSDN docs that IDbCommand
implements IDisposable
and therefore should be disposed of with a using
block.