We help IT Professionals succeed at work.
Get Started

SP to kill a process automatically is that process has been running for a hour.

Last Modified: 2014-02-25
Dear all,

right now we keep having Oracle query to the MS SQL send from the Oracle gateway, some time it rans fast and sometimes it hold there for serveral days and make the tempdB full and MS SQL operate anymore:

I usually run the follow query to query the sys.sysprocess to see their login time and how long it has been ran. Then if I see a the login used by the oracle to query MS SQL and it takes much longer than expected, I will use the spid to kill that by:

SELECT spid, loginame, program_name, hostname as "From host", login_time, last_batch, DB_NAME(dbid) AS "Against database" , 
(SELECT text FROM sys.dm_exec_sql_text(sql_handle))as "Query executed" 
FROM master..sysprocesses WHERE loginame= 'ixapi' and open_tran > 0

Open in new window

Any SP script you guys can introduce so that:

1) to build a SP that run that query by using the script above, and if the time it takes is more then one hour, it look at the SPID.
2) it create the kill commmand with the spid number as a string.
3) it execut the whole kill command with taht SPID we need one by one, if there are more than one result from the query about( it is rared to see but it did happen!)
4) email the statement, host, program name, loginname of each spid killed to the DBA (the operator is functional already) so that they know something anormal was happened.

any example is good for me to do it.
Watch Question
This problem has been solved!
Unlock 4 Answers and 34 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE