Georged Weblog

Have you georged your mind?

And execution continues

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.

 

Posted: Mar 09 2004, 09:57 PM by georged | with 6 comment(s)
Filed under:

Comments

Ryan Gregg said:

I have to completely agree with you. I've been bitten more than once by the fact that ASP.NET will finish out a page request even if you stop the debugger. Hopefully this will be changed in the future.
# March 9, 2004 9:40 AM

Teucer said:

OMG :o
# March 9, 2004 10:02 AM

AndrewSeven said:

Are you saying that when you detach the debugger from the process that the process continues?

Would you rather it simply stopped and thus never called your finally block?
Might that not cause debugging to not free up/dispose resources?

What would you expect if you were inside a using(){} block?
Would IDispose be called?

# March 9, 2004 1:18 PM

George Doubinski said:

Andrew, good points
> Are you saying that when you detach the debugger from the process that the process continues?
I'm not detaching debugger - I'm stopping the process in which case I do not expect execution to continue.

I'm not any good at debugger core but my expectation would be for debugger to call any finally blocks currently on stack and correctly call Dispose for using() resources.
Disposable resources overall should not be a problem as GC can kick in and dispose of them later.

Interestingly enough, sometimes code does not execute and I can clearly see Dispose() being called on connection as there is a Rollback in SQL trace. That's the behavior I expect, that's the behavior I consistenly observe in Windows and Console apps. What drives me nuts is that ASP.NET seems to have barely documented life of its own (swallowing some exceptions is another example).
# March 9, 2004 8:54 PM

George Doubinski said:

Come to think about it, I'm not sure that I want finally blocks to be called either. I want execution to stop, full stop :)

GC can take care of any disposable resources and most if not all unmanaged resources should be gone with the process (noone seems to be concerned with resources when killing process in task manager :)
# March 9, 2004 9:06 PM

TrackBack said:

^_^,Pretty Good!
# April 9, 2005 12:59 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)