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.
IDbConnection and using blocks in c#
934 Views Asked by jfin3204 At
2
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 notIDisposable
, 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
implementsIDisposable
and therefore should be disposed of with ausing
block.