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
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
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.
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.
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 :)
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)).
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
}