Kill–use this weapon carefully in SQL SERVER . TIP #90

When we heard “Kill” then first impression of this word is very bad. We always scare with this word.

In real world we never want this action  from anyone but in SQL Server case it is very helpful and help us many times.

This feature we can use but very carefully. It is something like we have to kill a cruel giant not the common innocent person.

Lets understand this by an example.

Suppose we wrote a stored procedure or function and by mistake we wrote a condition which is never ending. We didn’t realize this and when we run the stored procedure/function the SQL Server hangs , system is slow and many other issues occur and our stored procedure which we run still running and laughing on us.

In such situation we have to kill that particular stored procedure execution statement which is cruel giant and eating the resources.

See below statement

  SELECT ‘Infinite Loop’

It is never ending loop. and it is running on our SQL SERVER and will never stop.

Now first step is to Identify the process id for this statement for this we can use either sp_Who or sp_who2 which we discussed in TIP #82.

Now when we run it you will find on Database “IndiandotnetDB” we have a SPID 53 which is last statement on below image. This SPID 53 is reference of above while loop which we have to stop any ways.


Now we know SPID so we can stop or KILL  as shown below the syntax is very simple of KILL



Now we are good to go.

Note: Please use this KILL statement very carefully.

I hope this tip will help you some where to KILL or stop SQL SERVER enemies.

Enjoy !!!


How to kill a running SQL Statement ?

ello Friends,

As in my previous post you are aware of what are the different SQL Statement is currently running on your machine. Now each statement having particular individual process id. You can find the column spid in the Statement result.
So just pickup that process id and run following command.
KILL “process id”

Example :- KILL 59


Thanks & Regards
Rajat Jaiswal

How to Start and kill a process (exe) From dot net

Hello friends,
First of all sorry for such a late post bit busy in some other stuff but come back with bang.
Today I will show you some simple but very interesting topic. So first topic is how to call a process from your code. And how to kill a particular process from your code.
Its code is very simple just needs to understand once then you are perfect in this.
The first thing you need to know there is base class for process which is System.Diagnostics
I am showing you code right here so please with me for few moments.
I am opening a Microsoft word application here.

Imports System
Imports System.Diagnostics
Imports System.Diagnostics.Process

Private Sub btnStartProcess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStartProcess.Click
Dim oProcess As Process
Dim startInfo As New ProcessStartInfo
startInfo.FileName = “winword.exe”
oProcess = Process.Start(startInfo)
Catch ex As Exception
Throw ex
End Try
End Sub

In this way you can open a new Microsoft word application in similar manner you can open different other process. And also pass. Command line arguments to them.

Now if you want to close this application then its also easy. Just see below code and you will be master in that.

Private Sub btncloseProcess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncloseProcess.Click
Dim oProcess As Process
Catch ex As Exception
Throw ex
End Try
End Sub

If you know the id of process then it could be more specific. To kill particular instance.
In this way you can create and kill a process.
In next session I will come up with some more interesting topics till than do your best enjoy programming, enjoy dot net.
Thanks & regards