可能重複:
in a 「using」 block is a SqlConnection closed on return or exception?使用關閉SQL連接的功能帶來了
會這樣using
關閉此_connection
?
using(SqlConnection _connection = Class1.GetSqlConnection())
{ //code inside the connection
}
//connection should be closed/ended?
我只是想知道,因爲GetSqlConnection()
是Class1
一個靜態函數和整個連接可能不被關閉,因爲它是主叫外線類的靜態函數,而不是直的?
using(SqlConnection _connection = new SqlConnection(_connectionString)
{ //code inside the connection
}
是的,它會關閉連接。 – Enigmativity