Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

close/kill transaction

I have this open transaction, according to DBCC OPENTRAN:

Oldest active transaction: SPID (server process ID) : 54 UID (user ID)            : -1 Name                     : UPDATE LSN                      : (4196:12146:1) Start time               : Jul 20 2011 12:44:23:590PM SID                      : 0x01 

Is there a way to kill it/ roll it back?

like image 487
cs0815 Avatar asked Jul 26 '11 17:07

cs0815


People also ask

How do you kill transactions?

If you are confident that you can sever this connection you can use: KILL 54; Just be aware that depending on what the session was doing it could leave data and/or the app that called it in a weird state. Another easy way to see all open transactions on a server is pressing CTRL+1 in query window.

How do you close a transaction in SQL?

Right click on that line and select 'Kill Process'. A popup window will open for you to confirm that you want to kill the process. Once this is done, the process will be terminated and all uncompleted transactions will begin the rollback process.

How do I kill a SQL connection?

Right-click on a database in SSMS and choose delete. In the dialog, check the checkbox for "Close existing connections."


1 Answers

You should first figure out what it was doing, where it came from, and if applicable how much longer it might be expected to run:

SELECT     r.[session_id],    c.[client_net_address],    s.[host_name],    c.[connect_time],    [request_start_time] = s.[last_request_start_time],    [current_time] = CURRENT_TIMESTAMP,    r.[percent_complete],    [estimated_finish_time] = DATEADD        (            MILLISECOND,            r.[estimated_completion_time],             CURRENT_TIMESTAMP        ),    current_command = SUBSTRING        (            t.[text],            r.[statement_start_offset]/2,            COALESCE(NULLIF(r.[statement_end_offset], -1)/2, 2147483647)        ),    module = COALESCE(QUOTENAME(OBJECT_SCHEMA_NAME(t.[objectid], t.[dbid]))         + '.' + QUOTENAME(OBJECT_NAME(t.[objectid], t.[dbid])), '<ad hoc>'),    [status] = UPPER(s.[status])  FROM      sys.dm_exec_connections AS c  INNER JOIN      sys.dm_exec_sessions AS s      ON c.session_id = s.session_id  LEFT OUTER JOIN      sys.dm_exec_requests AS r      ON r.[session_id] = s.[session_id]  OUTER APPLY      sys.dm_exec_sql_text(r.[sql_handle]) AS t  WHERE      c.session_id = 54; 

If you are confident that you can sever this connection you can use:

KILL 54; 

Just be aware that depending on what the session was doing it could leave data and/or the app that called it in a weird state.

like image 98
Aaron Bertrand Avatar answered Sep 21 '22 06:09

Aaron Bertrand