c# - without - Will a using block close a database connection?
using connection c# open (3)
A using block will ensure the destruction of DbConnection object by calling the Dispose() method. The Dispose() method will in turn call the Close() method and has to wait for it to finish closing the connection to the database.
https://code.i-harness.com
using (DbConnection conn = new DbConnection())
{
// do stuff with database
}
Will the using
block call conn.Close()
?
Yes - http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.close.aspx
edit: from Microsoft: "The connection is automatically closed at the end of the using block."
surely yes because it will dispose the connection and before disposing the inner logic of the connection calls the close.