I have a scenario mentioned below :
Create table Employee(Sno int primary key,EmpName varchar(10))
GO
begin try
Begin tran TranOne
insert into employee values(1,'A')
insert into employee values(1,'B')
Commit tran TranOne
END Try
Begin Catch
Print 'In Catch'
--If @@trancount>0
--rollback
End catch
dbcc opentran
Executing above set of statements leaves the transaction TranOne open. After its completion I run dbcc opentran in same session. Now how can I get the query that is executing under the open transaction TranOne. If I do dbcc inputbuffer or sys.dm_exec_request I get the last query executed in the session which is dbcc opentran and also the process state is sleeping.