Will a using block close a database connection?

前端 未结 4 405
伪装坚强ぢ
伪装坚强ぢ 2020-12-03 04:07
using (DbConnection conn = new DbConnection())
{
    // do stuff with database
}

Will the using block call conn.Close()?<

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-03 05:08

    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."

提交回复
热议问题