Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check that there is transaction that is not yet committed in SQL Server 2005?

Does anyone know the command to check if there is an un-committed transaction in SQL Server 2005?

like image 658
pang Avatar asked Jun 11 '09 09:06

pang


People also ask

How do you find uncommitted transactions in SQL Server?

Two things to check. One is that you might have the "implicit transaction" setting turned on, which means EVERYTHING it wrapped in a transaction. Check the properties of the server/database. Otherwise, you can use the DBCC OPENTRAN function to find any uncommitted transactions....

How can I tell if a SQL Server transaction is running?

Using sys. dm_tran_active_transactions with other DMVs to find information about active transactions. The following example shows any active transactions on the system and provides detailed information about the transaction, the user session, the application that submitted, and the query that started it and many others ...

What happens if you don't commit transaction SQL?

As long as you don't COMMIT or ROLLBACK a transaction, it's still "running" and potentially holding locks. If your client (application or user) closes the connection to the database before committing, any still running transactions will be rolled back and terminated.


2 Answers

use @@trancount or sys.dm_tran_active_transactions DMV in sql 2005, 2008

like image 110
Mladen Prajdic Avatar answered Nov 08 '22 01:11

Mladen Prajdic


XACT_STATE() reports the transaction state of a session, indicating whether or not the session has an active transaction, and whether or not the transaction is capable of being committed. It returns three values:

  • 1, The session has an active transaction. The session can perform any actions, including writing data and committing the transaction.
  • 0, There is no transaction active for the session.
  • -1, The session has an active transaction, but an error has occurred that has caused the transaction to be classified as an uncommittable transaction. The session cannot commit the transaction or roll back to a savepoint; it can only request a full rollback of the transaction. The session cannot perform any write operations until it rolls back the transaction. The session can only perform read operations until it rolls back the transaction. After the transaction has been rolled back, the session can perform both read and write operations and can begin a new transaction.

@@TRANCOUNT Returns the number of active transactions for the current connection.

  • 0, not in a transaction
  • 1, in a transaction
  • n, in a nested transaction
like image 26
KM. Avatar answered Nov 08 '22 01:11

KM.