views:

186

answers:

1

My application (C++ using SQL Native Client with SQL Server 2000) is consistently finding its way into a hanging state. I believe this is because a transaction is left uncommitted someplace on a table and a SELECT query on that table, as a result of the open transaction, is blocking.

Unfortunately, I'm really having trouble determining where the hanging transaction might be in my code. Is there any way to get SQL Server to indicate what queries have been run on an uncommitted transaction?

+3  A: 

if you have admin (sa) proviliges, you can run sp_Who, or sp_Who2 to show all server activity, by Spid, Run

Exec sp_Who2 [SpidNumber]

to just see the one session you are interested in...

To directly see open transactions, run

DBCC OPENTRAN (T-SQL) Displays information about the oldest active transaction and the oldest distributed and nondistributed replicated transactions, if any, within the specified database. Results are displayed only if there is an active transaction or if the database contains replication information. An informational message is displayed if there are no active transactions.

Syntax
DBCC OPENTRAN 
    (    {'database_name' | database_id}
    )    [    WITH TABLERESULTS [, NO_INFOMSGS]
        ]

Sql Server should, however, automatically rollback any open transaction when a user session is terminated.

Charles Bretana
That's got me half way there. I have an SPID that is likely to blame now. Is there anyway to dig a bit deeper to see what queries have been executed in the SPID?
antik
You can try running the "profiler" tool, it is one of the SQL Server client tools installed on your workstation. It constantly monitors/reports on everything running on Server, and has spid filter (among others)
Charles Bretana
DBCC INPUTBUFFER ordeclare @handle binary(20)select @handle = sql_handle from master.dbo.sysprocesses where spid = 84select * from ::fn_get_sql(@handle)
gbn
@gbn: you might make that into an answer instead of a comment...
antik