I did some research and found an answer which I summarized below. For a more detailed explanation, see here
The using
statement for SqlCommand
does not dispose of a whole lot. SqlCommand
indirectly inherits from Component
which implements a finalizer. Unless the implementation has changed, the GC ignores objects with a finalizer the first time it encounters an out-of-scope one. Instead of removing it from memory, the GC calls the finalizer and then moves on. The second time it encounters it, the GC will remove the object from memory. This is obviously rather expensive so you do not want the finalizer to run very often.
To prevent the finalizer from running, Component
(which SqlCommand
indirectly inherits from) implements a dispose method that tells the GC not to call the finalizer since the dispose method already handled any cleanup.
In a nutshell, the using
statement around SqlCommand
doesn't do anything special, but it prevents the more expensive finalizer from being called.
If you have more details into how this works, please let me know in the comments.
Fill()
manage connection itself even you r not usingusing
statement.