S
Steven Livingstone
After looking at a number of posting (many with close v dispose etc), I am
interested in whether the following code is the best way to ensure your
transaction behaves as expected and your connection gets closed as well as
connection and transaction both disposed.
using (SqlConnection conn = new SqlConnection(connectionstring))
{
using (SqlTransaction trans = conn.BeginTransaction())
{
try
{
Update1();
Update2();
trans.Commit();
}
catch (Exception ex)
{
trans.Rollback();
}
finally
{
conn.Close();
}
}
}
interested in whether the following code is the best way to ensure your
transaction behaves as expected and your connection gets closed as well as
connection and transaction both disposed.
using (SqlConnection conn = new SqlConnection(connectionstring))
{
using (SqlTransaction trans = conn.BeginTransaction())
{
try
{
Update1();
Update2();
trans.Commit();
}
catch (Exception ex)
{
trans.Rollback();
}
finally
{
conn.Close();
}
}
}