Nothing makes our life more interesting than ASP.NET behaviour at debugger termination. This is a short version of three lost hours:
Create an empty page and add the following code
private void Page_Load(object sender, System.EventArgs e)
{
const string CONNECT_STRING = "server=(local);uid=sa;pwd=password;database=msdb;persist security info=True";
SqlConnection con = new SqlConnection(CONNECT_STRING);
con.Open();
SqlTransaction tran = con.BeginTransaction();
try
{
new SqlCommand("create table temptable(id int)", con, tran).ExecuteNonQuery();
tran.Commit();
}
catch
{
tran.Rollback();
throw;
}
finally
{
con.Close();
}
}
Add breakpoint at “new SqlCommand“ line and hit F5
When debugger stopped at breakpoint hit Shift-F5.
And here is trace from SQL Profiler:
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;BEGIN TRANSACTION
go
create table temptable(id int)
go
COMMIT TRANSACTION
go
Seems that ASP.NET is entitled to do whatever it wants at debugger termination including successful execution of the entire program.
NOT sweet.