Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jul 06, 2011 03:17 PM by andyrwebman
Feb 07, 2007 09:43 AM|LINK
When debugging the server-side code of my ASP page, if I stop debugging (via the 'Stop Debugging' option on the debug menu or the equivalent tool-bar button) although this appears to stop the debugging session, it actually executes the subsequent code.
(I am using Visual Studio 2005 SP1 and IE7, running under Windows XP Professional.)
Steps to reproduce the issue:
1. Create a new table in your SQL Server database called 'Table1', containing a varchar(50) column called 'Column1'.
2. Create a new ASP.Net web site (using C#).
3. Add an ASP button control to the 'Default.aspx' page and double-click it to create the event handler.
4. Add a reference to the 'System.Data.SQLClient' namespace.
5. Paste the following routine into the 'Default.aspx.cs' file:
private bool AddRecord()
SqlConnection cnn = new SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=YourDB;Data Source=(local)");
SqlCommand cmd = new SqlCommand("INSERT INTO Table1 (Column1) VALUES ('This record should not exist')", cnn);
cmd.CommandType = CommandType.Text;
catch (Exception ex)
(You will have to adjust the connection string as appropriate for your database.)
6. Add a call to the 'AddRecord' function into the 'Button1_Click' function like so:
protected void Button1_Click(object sender, EventArgs e)
7. Put a breakpoint anywhere before the line 'cmd.ExecuteNonQuery();'.
8. Run the project in debug and when it hits the breakpoint - stop it.
9. Examine the contents of Table1, it should have a record in it, despite the fact that the SQL insert command should not have been executed.
Feb 07, 2007 02:26 PM|LINK
Are you using IIS or development server?
Feb 07, 2007 03:27 PM|LINK
Mar 29, 2007 05:17 PM|LINK
I have also noticed this also and it has burned me big-time. This has got to be a major bug in VS. I have found that it only executes that 'block' of code it is in after you stop the Debugger. If somebody knows a way to stop the Debugger on the line
it is stopped on, PLEASE let me know. This is very dangerous. I actually noticed it in VS 2003 also when I used IIS - and I also notice it now when in VS 2005 using the development server.
Mar 30, 2007 08:34 AM|LINK
It's good to know that someone else has experienced this issue. It stops you thinking that you are going mad or that there is something wrong with your PC's setup.
Aug 30, 2007 08:34 PM|LINK
Has anyone found a workaround for this?
Sep 17, 2007 09:27 AM|LINK
I tried it too ,am facing the same issue , must be a bug associated with the debugger of Visual Studio 2005. This is a cool bug found in Visual Studio 2005 [;)]
Thanks & Regards
Feb 05, 2008 08:50 AM|LINK
This still happens in Visual Studio 2008 (VS2008). They should really publicize this sort of thing. If you stop it just before executing code that updates a live database (thinking it won't do it) you can be in deep trouble when it updates the db anyway.
The only solution I found is to Set the Next line to execute to the last line of the function before hitting the
Stop Debugging button.
Feb 06, 2008 12:32 AM|LINK
This is because by default, Visual Studio will detach from the ASP.NET process instead of terminating it. If you would prefer the debugger terminate the ASP.NET process, there is a 'Debug->Terminate All' menu item. I believe that this command is hidden by
default for some profiles, so you may need to switch to the general profile, or unhide this command to use it.
Alternatively, web application projects (File->New Project instead of File->New Web Site) have a project option to 'Enable Edit and Continue'. If you enable this option, the debugger will terminate the ASP.NET process as part of start debugging.
Visual Studio Debugger Developer
Feb 07, 2008 12:37 PM|LINK
Indeed, Using Terminate All kills off the Development Server therby making sure the code does not continue to execute.
You second idea of using a Web application project instead of a Web site project means radically changing the way you develop your site so I'm not sure this is suitable to solve the problem discussed.