Does End Using close an open SQL Connection Does End Using close an open SQL Connection sql-server sql-server

Does End Using close an open SQL Connection


Exiting a using block calls .Dispose() on the object in question (cn in your example) which for a SqlConnection will close the connection and any open resources.


More precisely calling Dispose or Close will mark the underlying physical connection as "Not in use" - but doesn't really close it. A "Not in use" connection that isn't yet physically closed is thus available for pooling. Therefore - calling Dispose would return a connection to the connection pool.


According to MSDN you don't need the close statement.

"The following example creates a SqlConnection, opens it, displays some of its properties. The connection is automatically closed at the end of the using block." -- http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.close.aspx