tags:

views:

160

answers:

5

i created a loop up to 100 to insert any data in db. but when i close my browser I hope it stops but it in background it continues looping and filling my db. how can I stop it?

thanks

A: 

Shut down SQL Server and/or IIS.

Edit: ...assuming that you made a programming mistake, you DB keeps filling up and you desperately want to stop it -- this is how I understood your question.

Heinzi
hope it works with iis stop because sql server is remote. Thanks
snarebold
I like to test a big procedure.. but anytime I like to stop it.
snarebold
OK, in that case, the most elegant solution would probably be to put the INSERT code into a background thread and make a STOP button on your aspx page which stops this thread.
Heinzi
BTW: I would appreciate it if someone could either explain or "fix" the downvote...
Heinzi
Thanks ............ :-)
Heinzi
+2  A: 

If you are doing this at the server in a single http request (for example, responding to a button event in your code-behind), then the server doesn't really care much about the browser. If you want the inserts to stop when the browser stops, I would suggest perhaps doing this via an ajax loop - but note that this will be considerably slower, as you will have 100 round-trips, and 100 separate sets of processing at the server.

Marc Gravell
+1  A: 

How about a band-aid solution:

Let your webpage send keep-alive AJAX calls every 5 seconds or so to the server and abort if the keep alive is not received :)

Crimson
+3  A: 

It sounds like you have started off this process from an ASP.NET form with the server-side code doing the looping in response to something (either the ASP.NET form loading, or clicking a button etc).

Note that closing your browser window will NOT stop any long-running code process that you have invoked on the "server". Although this may be running on the same machine, the "server" here is the IIS/Cassini process that serves up your webpage to the "client" (your browser).

In order to stop this, you'll need to stop/shutdown the IIS or Cassini (Cassini small web server used by Visual Studio when running a web app on your local development machine), or stop/shutdown the SQL Server process.

EDIT: I noticed the downvotes for the other answer than mentions stopping IIS/SQL. This, of course, is a "last-gasp" mechanism for stopping a long-running process invoked by the "client" but running on the "server". If this were to be done in a "real" application, and you wished to allow the user to cancel a long-running application, an approach as suggested by Marc would be required (i.e. use AJAX, "poll" the web-page with AJAX "refreshes" and respond to subsequent user input (i.e. button click)).

CraigTP
+3  A: 

No guarantees that it would work, but you could try the HttpResponse.IsClientConnected property.

for (int i = 0; i < 100; i++)
{
    if (!Response.IsClientConnected) break;

    // insert the next row
}
LukeH
Wow! I like you. This works. many thanks.
snarebold