Killing a blocking process
This recipe illustrates how you can kill a blocking process in SQL Server.
Getting ready
In order to see blocking processes in your list, we will have to force some blocking queries. If you have already done the prep work in the List running/blocking processes recipe, you do not need to do this prep section. If you haven't, go ahead and perform this section:
Open SQL Server Management Studio. Connect to the instance you want to test. We will assume you have AdventureWorks2008R2
. If not, you can use a different database and table altogether.
Open two new query windows for that connection. Type and run the following in the two query windows:
USE AdventureWorks2008R2 GO BEGIN TRAN SELECT * FROM dbo.ErrorLog WITH (TABLOCKX)
How to do it...
Open the PowerShell console by going to Start | Accessories | Windows PowerShell | Windows PowerShell ISE.
Import the
SQLPS
module, and create a new SMO Server object as follows:#import SQL Server module Import-Module SQLPS -DisableNameChecking...