08-02-2004, 03:02 AM | #1 (permalink) |
Banned from being Banned
Location: Donkey
|
Anyone notice how .net still runs code after you hit "stop"?
(Sorry, worded the subject wrong... should be "the Visual Studio .net 2003 Debugger" instead of plain ol' ".net")
What's up with this? Say you breakpoint a line and have some code underneath that inserts a few records into a table in a database. Lines go somewhat like this: init variables open db connection insert records close db connection If you breakpoint on the init variables part and step through the code and realize "oh, I just spotted an error in my code" and hit stop, all the code beyond that is still executed, or in this case, records will be inserted into the table. Why does it do this? Isn't that potentially dangerous in the sense that even though you spotted the error and hit stop, your code will still follow through? Basically it kinda sucks for me right now because I need to run this app and breakpoint it to see how data will look before going in, but in order to prevent it from actually executing the SP, I have to rename it on the server so when it's called, it errors out.
__________________
I love lamp. Last edited by Stompy; 08-07-2004 at 10:22 AM.. |
08-03-2004, 02:00 AM | #2 (permalink) |
Psycho
Location: I think my horns are coming out
|
I know for a fact that VB 6, nor VC++ 6 did not do that.
So I guess this is another testament to how badly .Net sucks. Why do you use .Net BTW?
__________________
Do not confuse altruism with kindness, good will or respect for the rights of others. These are not primaries, but consequences, which, in fact, altruism makes impossible. The irreducible primary of altruism, the basic absolute, is self-sacrifice - which means: self-immolation, self-abnegation, self-denial, self-destruction - which means: the self as a standard of evil, the selfless as a standard of the good. |
08-03-2004, 10:17 AM | #3 (permalink) |
Banned from being Banned
Location: Donkey
|
How would that be a testament to how bad .net sucks? The Visual Studio Designer is making this error, not the framework.
I use .net because it's a great development platform and is better than anything I've used before (and I've used all of em, including java)
__________________
I love lamp. |
08-05-2004, 06:37 AM | #4 (permalink) | |
Psycho
Location: the hills of aquafina.
|
Quote:
__________________
"The problem with quick and dirty, as some people have said, is that the dirty remains long after the quick has been forgotten" - Steve McConnell |
|
08-05-2004, 01:11 PM | #5 (permalink) |
Crazy
|
I've been working with the .NET framework since it was in beta (off and on) and I've never seen that in VS 2K2 or 2K3. Are you sure you are stopping the code? If it's really a problem you can just comment out the line that does the DB insert while you are debugging.
|
08-06-2004, 03:22 AM | #7 (permalink) |
Upright
|
I assumed garbage collection would run after you stopped your code, but for your code to keep executing after you hit stop just doesnt make sense.
Are you sure your stopping where you think your stopping? Place a break point near the start of execution and step through your code to make sure you are where you think you are. |
08-06-2004, 06:25 AM | #8 (permalink) |
Banned from being Banned
Location: Donkey
|
Load up a new asp.net project.
Add a button to the default webform and add the following code to the click event (don't forget to include "using System.Data.SqlClient;" at the top): Code:
private void Button1_Click(object sender, System.EventArgs e) { SqlConnection conn = new SqlConnection("server=127.0.0.1;uid=sa;pwd=mypass;database=Northwind"); SqlCommand cmd = new SqlCommand("INSERT INTO dbo.Categories (CategoryName) VALUES (@CategoryName)", conn); cmd.CommandType = CommandType.Text; cmd.Parameters.Add(new SqlParameter("@CategoryName", SqlDbType.NVarChar, 15)); cmd.Parameters["@CategoryName"].Value = "test"; conn.Open(); cmd.ExecuteNonQuery(); cmd.Dispose(); conn.Dispose(); } When the debugger reaches that point, hit stop. Look in your northwind database and you will see a category called "test". Even if you breakpoint on conn.Open(), the category is added. This does it on all of my development machines (4), so I don't think it's a botched install. [edit] I just tried this in a plain old windows forms application and there is no bug, so perhaps it's an error in the asp.net worker process.
__________________
I love lamp. Last edited by Stompy; 08-06-2004 at 06:32 AM.. |
08-07-2004, 10:21 AM | #10 (permalink) | |
Banned from being Banned
Location: Donkey
|
Quote:
And I'm not sure about what you're asking regarding the trace... the same exact code is being sent as if you were to execute the click event without any breakpoints. The designer is basically ignoring the fact that you hit "stop" and is executing the code regardless. Did any of you try it? If so, what were the results?
__________________
I love lamp. Last edited by Stompy; 08-07-2004 at 10:24 AM.. |
|
08-07-2004, 04:48 PM | #11 (permalink) |
Crazy
|
I'll try it Monday at work (I only do WinForm development here at home. Just little applications for myself). But I do that exact kind of code almost every day and I've never had a problem with code executing after I've hit "stop" in the debugger. You say "If you comment it out, nothing will happen, of course," but if you hit stop when you have a breakpoint set on that line that line shouldn't execute of course. This tells me that you're doing something differently than I do when I'm debugging. So you set a breakpoint and the code stops, do you hit F5 then or click the "stop" button in the debugger? If you set a breakpoint at the event handler declaration "private void Button1_Click(" and then run the code, stopping when you get to the event handler, does the SQL statement still get executed? How are you stopping execution of the code? When you hit the breakpoint and step through the code using F11 what happens? I'm taking you through the same kinds of steps I would use if I ran into this problem.
You can use the SQL Profiler to start a trace and watch the activity on a specified database. That'll show you the SQL being executed against the database and when it is executed. |
08-07-2004, 07:44 PM | #12 (permalink) |
Banned from being Banned
Location: Donkey
|
If you breakpoint the conn.Open() AND the cmd.ExecuteNonQuery() statements, once you hit stop in the debugger (by clicking the "stop" button on the toolbar), the code will still execute. To me, this shows that it's something in the background, and since it only happens on asp.net projects... I can only assume the worker process.
I had a friend of mine try this on his machine and it does the same thing to him. It's funny that no one has experienced this, because I've been dealing with this issue for AGES now and I'm starting to get pretty fed up with it
__________________
I love lamp. Last edited by Stompy; 08-07-2004 at 07:47 PM.. |
08-10-2004, 07:28 PM | #14 (permalink) |
Crazy
|
argh, I've been in meeting hell for the past two days! Tomorrow I'm chaining myself to my desk though so I'll try it then. I saw a post on a blog somewhere today talking about this exact problem (was it you?) and the solution was some setting like "debug unmanaged code = true" which seemed odd to me since I thought the ASP.NET process was all managed code.
I'll try it out and try debugging it with WinDbg to see if I see the same behavior. |
08-14-2004, 10:02 PM | #15 (permalink) |
Tilted
Location: So. Cali
|
wow, when I first read this i thought you were on crack..but tried it on a project that I am working on and it definitely happens... If i break on my connection.open statement and hit stop then the query isnt executed..but if i step past that to the next line (cmd.connection = conn) and stop, it continues on and executes the query... very odd.
__________________
Tell me what we’re fighting for— I don’t remember anymore, only temporary reprieve. And the world might cease if we fail to tame the beast; from the faith that you release comes an atheist peace. |
08-16-2004, 07:12 PM | #16 (permalink) |
Insane
|
This is just another part of server-side programming.
I've written plenty of scripts in the past that looped longer than I wanted. Even when I hit stop, the server was still going. The problem lies within the engine over on the server. If you are legitimately stopping your app and the server is still crunching numbers, then I'd say something is definately up with .NET (this would not surprise me at all) |
Tags |
code, hit, net, notice, runs, stop |
|
|