KILL command cannot be used inside user transactions.

Error Message:
Msg 6115, Level 16, State 1, Line 1
KILL command cannot be used inside user transactions.

Severity level:
16.

Description:
This error message appears when you try to use the KILL command inside a user transaction.

Consequences:
The T-SQL statement can be parsed, but causes the error at runtime.

Resolution:
Errors of the Severity Level 16 are generated by the user and can be fixed by the SQL Server user. The statement cannot be executed this way. You must remove the explicit transaction.

Versions:
All versions of SQL Server.

Example(s):
DECLARE @i INT
DECLARE @stmt NVARCHAR(100)
SELECT @i = @@SPID
SET @stmt = ‘KILL ‘ + CAST(@i AS NVARCHAR(2))
BEGIN TRAN
EXECUTE sp_ExecuteSQL @stmt
COMMIT TRAN

Remarks:
In the above example we try to terminate the current session inside a user transaction. This raises the error.

]]>

Leave a comment

Your email address will not be published.