Reputation: 3525
What is the difference between TransactionScope in dot net and Transaction in SQL
protected void Page_Load(object sender, EventArgs e)
{
int i = 0;
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
{
i = 1;
}
Response.Write(i.ToString());
}
I get the value 1 displayed by Response.Write(). Why? scope.Complete wasnt executed. Hence the i value should rollback to 0;
Upvotes: 0
Views: 563
Reputation: 15252
Basically the same thing; TransactionScope is the newer .NET version and the recommened version to use if you are coding on ASPNET 2.0 upwards.
using (TransactionScope scope = new TransactionScope())
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlHelper.ExecuteNonQuery(connectionString, CommandType.StoredProcedure,
"Update1");
SqlHelper.ExecuteNonQuery(connectionString, CommandType.StoredProcedure,
"Update2");
}
scope.Complete();
}
Upvotes: 1