Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 SQL Server Administration (2008)
 How to kill INSERT statement?

Author  Topic 

fralo
Posting Yak Master

161 Posts

Posted - 2011-07-29 : 10:01:44
I have a web application. When executed, the sql code writes records to a table. The INSERT statement is within a loop, but not an infinite one, thank goodness. Unless I can stop it, it will continue to fill up the table for hours on end. How can I kill this process? I tried shutting down sql server agent. But it automatically restarts on its own after a few seconds. When I check my table it's still growing, so I know it's still running. I also tried shutting down IIS.

Your help is greatly appreciated.

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-07-29 : 10:10:54
If it is a one-time thing (and I hope it is!), you can run sp_who2 in SSMS, identify the row to get the spid and issue the command
kill spid
(where spid is a number).

You may also want to install sp_whoisactive (http://www.sqlmag.com/article/sql-server/sp_whoisactive) which is one of the highly recommended free tools that helps you find all kinds of things about what is running on a server.
Go to Top of Page

fralo
Posting Yak Master

161 Posts

Posted - 2011-07-29 : 10:18:41
Okay, I'm new to this.

So running 'exec sp_who2' will return a list from which I must choose the correct spid?

I then execute 'kill <spid>'.
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-07-29 : 10:26:26
Yes.

When you run sp_who2, it gives you a few pieces of information which (hopefully) will help you identify the spid of the offending process. Once you identify the correct spid, then you can kill it. Unless you can identify the spid correctly, don't kill something based on suspicion.
Go to Top of Page

fralo
Posting Yak Master

161 Posts

Posted - 2011-07-29 : 10:50:31
I'm fairly confident of which one (or two) is the culprit.

In looking at the output..

1) the 'Hostname' field is the IIS server name.
2) the 'Login' is the login specified in my connection string within the source code.
3) the 'ProgramName' field is Internet Information Services.

There's also another one with these same fields except the ProgramName is .Net SqlClient Data Provider.

I'm torn between the two.

Any thoughts?
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2011-07-29 : 11:30:44
DBCC INPUTBUFFER(@spid) will show you the statement being executed.

Also, be aware if you kill it, that the rollback could take an awful long time too.
Go to Top of Page

3magic
Starting Member

14 Posts

Posted - 2011-08-03 : 08:12:16
Use while loop for this.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-03 : 08:19:55
you might be better off converting this to set based insert

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

muratos
Starting Member

22 Posts

Posted - 2011-08-04 : 04:43:16
You can also use Activity Monitor and trace what is going on your SQL Server real time (at the refresh intervals you set). It supports getting all query details and killing it by menu. It is a GUI and suits for beginners.
Go to Top of Page
   

- Advertisement -