How to find active open transactions in SQL Server 2008R2

15
68321
active open

Friends,

In this post we are gonna discuss about the way to find the OPEN and ACTIVE Transactions in Sql Server. To explain the same I created a table with the below given script.

Create table Employee
(
Emp_ID int,
Emp_Name Varchar(50),
Dept Varchar(50),
Desig Varchar(50)
)

To check the Open Transactions you can follow any one of the following ways.

  • select @@TRANCOUNT
  • DBCC OPENTRAN

Both the above Sql statements returns the Open transactions details. The first one gives you the count of OPEN transactions where as the second gives you the details of the open transaction. First let me execute the same and see whether any open transactions are available.

I am getting the following message when I execute DBCC OpenTran query.

“No active open transactions.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.”

and when I execute the second one i.e “select @@TRANCOUNT” statement.

From the above Pic and the Error Message, it is clear that there are NO ACTIVE OPEN transactions. Now let me execute the following query which OPENS the transaction but not Close.

Begin Tran
insert into Employee Values(1,’Roopesh’,’PL’,’IT’)
insert into Employee Values(2,’Lokesh’,’PM’,’IT’)

The query executed successfully and now lets execute the above commands to check the status of the open transactions.

 

You can see that the command is proving the open transaction details. Now let me execute the following command to Commit the transaction i.e Active.

“Commit tran”

Now if I execute the DBCC command again, you can see the following message which says that there are NO OPEN TRANSACTIONS.

“No active open transactions.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.”

This is how you can get the details about the open transactions and there is one more way i.e by using the following SYSTEM tables.

select * from sys.dm_tran_active_transactions
select * from sys.dm_tran_database_transactions
select * from sys.dm_tran_session_transactions

The above tables stores the information about ACTIVE Transactions,Database Transactions and Session Transactions respectively. You can make use of these queries to get MORE details about OPEN and ACTIVE transactions.

SELECT
trans.session_id as [Session ID],
trans.transaction_id as [Transaction ID],
tas.name as [Transaction Name],
tds.database_id as [Database ID]
FROM sys.dm_tran_active_transactions tas
INNER JOIN sys.dm_tran_database_transactions tds
ON (tas.transaction_id = tds.transaction_id )
INNER JOIN sys.dm_tran_session_transactions trans
ON (trans.transaction_id=tas.transaction_id)
WHERE trans.is_user_transaction = 1 — user
AND tas.transaction_state = 2 — active
AND tds.database_transaction_begin_time IS NOT NULL

So .. That’s it and now you can track the open transactions easily .. 🙂

All the Best !!

Regards,
Roopesh Babu V

15 COMMENTS

  1. vibracion de motor
    Sistemas de ajuste: esencial para el desempeño suave y eficiente de las maquinarias.

    En el mundo de la ciencia avanzada, donde la rendimiento y la seguridad del sistema son de gran significancia, los aparatos de equilibrado cumplen un tarea crucial. Estos dispositivos específicos están desarrollados para calibrar y regular piezas rotativas, ya sea en dispositivos industrial, vehículos de movilidad o incluso en aparatos caseros.

    Para los técnicos en conservación de dispositivos y los ingenieros, utilizar con aparatos de ajuste es crucial para proteger el desempeño suave y estable de cualquier dispositivo dinámico. Gracias a estas opciones innovadoras avanzadas, es posible minimizar notablemente las vibraciones, el ruido y la carga sobre los sujeciones, aumentando la tiempo de servicio de componentes costosos.

    Igualmente importante es el rol que cumplen los aparatos de calibración en la atención al consumidor. El ayuda experto y el soporte constante empleando estos aparatos posibilitan brindar asistencias de gran calidad, aumentando la bienestar de los consumidores.

    Para los responsables de emprendimientos, la contribución en equipos de calibración y dispositivos puede ser fundamental para incrementar la rendimiento y rendimiento de sus aparatos. Esto es principalmente significativo para los emprendedores que administran modestas y modestas emprendimientos, donde cada detalle cuenta.

    Además, los equipos de equilibrado tienen una vasta aplicación en el sector de la fiabilidad y el monitoreo de excelencia. Posibilitan encontrar eventuales defectos, previniendo mantenimientos onerosas y perjuicios a los sistemas. Más aún, los indicadores obtenidos de estos equipos pueden emplearse para mejorar métodos y incrementar la visibilidad en motores de consulta.

    Las áreas de aplicación de los aparatos de ajuste comprenden diversas áreas, desde la manufactura de vehículos de dos ruedas hasta el control ambiental. No afecta si se habla de grandes manufacturas manufactureras o reducidos establecimientos de uso personal, los equipos de ajuste son esenciales para promover un funcionamiento eficiente y libre de paradas.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

40 − thirty four =