A well written program will always clean up it’s resources and with SqlConnection is no different. We should always open, use, close. Some people are paranoid about it and would do something like this:
3: conn = null;
Now that’s one dead connection! But is all this necessary? Should we call Close and Dispose? When should we call Close and when should we call Dispose?
Well, if we use the Red Gate’s free Reflector and browse to System.Data.SqlClient.SqlConnection and to the Dispose method we can see that it will in turn call the Close method:
The Dispose also clears it from the poolGroup and gets rid of the UserConnectionOptions. So if you are sure you’re not going to use this specific connection object anymore then you are safe to Dispose it which will also take care of the closing.
If you want to reuse the connection object just close it and re open it when necessary.