Search code examples
c#databaseusing

Will a using block close a database connection?


using (DbConnection conn = new DbConnection())
{
    // do stuff with database
}

Will the using block call conn.Close()?


Solution

  • Yes, it will; the implementation of DbConnection.Dispose() calls Close() (and so do its derived implementations).