SQL Server Error Msg 6104 – Cannot use KILL to kill your own process.

In this blog post, let’s learn about the error message “6104 – Cannot use KILL to kill your own process.” in Microsoft SQL Server, the reason why it appears and the solution to fix it.

SQL Server Error Message

6104 – Cannot use KILL to kill your own process.

Reason for the Error

SQL Server Error Msg 6104 “Cannot use KILL to kill your own process” occurs when you try to use the KILL command to terminate your own process. This error is typically encountered when you are connected to SQL Server using your own login and you try to kill your own session.

The KILL command is used to terminate a process running on SQL Server. However, you cannot use it to kill your own session because doing so would cause the connection to be lost, which could potentially lead to data loss or corruption.

Here’s an example of how this error can occur:

-- Connect to SQL Server using your own login
USE [AdventureWorks2019];
GO

-- Find your own SPID
SELECT @@SPID;

-- Attempt to kill your own process
KILL 69;

When you execute the KILL command in this example, you will receive the SQL Server Error Msg 6104, as you are trying to kill your own process.

(1 row affected)
Msg 6104, Level 16, State 1, Line 9
Cannot use KILL to kill your own process.

Solution

To resolve this error, you should use a different login to terminate the session or use a different method to end the process. One option is to use the SQL Server Management Studio to end the session. Here are the steps to do so:

  1. Open SQL Server Management Studio and connect to the database server.
  2. Navigate to the “Activity Monitor” tab in the Object Explorer.
  3. Locate the process that you want to end and right-click on it.
  4. Select “Kill Process” from the context menu.

Alternatively, you can also use the sp_who2 system stored procedure to identify the session that you want to terminate and then execute the KILL command using a different login. Here’s an example:

-- Identify the session that you want to terminate
EXEC sp_who2;

-- Use a different login to terminate the session
USE master;
GO
KILL 69;

In this example, you first use the sp_who2 system stored procedure to identify the SPID of the session that you want to terminate. Then, you switch to the master database and execute the KILL command using a different login. This way, you can terminate the session without encountering the SQL Server Error Msg 6104.

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

In this blog post, let’s learn about the error message “1459 – An error occurred while accessing the database mirroring...
In this blog post, let’s learn about the error message “7937 – Columnstore index has one or more missing column...