S
Servé La
What are the advantages and disadvantages of opening and closing database
connection in a web application in the following examples?
1: using(SqlConnection connection = new SqlConnection()) {}
2:
SqlConnection connection = null;
try
{
connection = new SqlConnection();
}
finally
{
if (connection != null) connection.Close();
}
3. SqlConnection connection = new SqlConnection();
...
connection.Close();
Is there a general preferred way?
connection in a web application in the following examples?
1: using(SqlConnection connection = new SqlConnection()) {}
2:
SqlConnection connection = null;
try
{
connection = new SqlConnection();
}
finally
{
if (connection != null) connection.Close();
}
3. SqlConnection connection = new SqlConnection();
...
connection.Close();
Is there a general preferred way?