Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.databases.ms-sqlserver > #1454

Re: How to find not-committed transaction in SQL Server 2008 exactly?

From Erland Sommarskog <esquel@sommarskog.se>
Newsgroups comp.databases.ms-sqlserver
Subject Re: How to find not-committed transaction in SQL Server 2008 exactly?
Date 2013-04-27 11:42 +0200
Organization Erland Sommarskog
Message-ID <XnsA1AF772983D12Yazorman@127.0.0.1> (permalink)
References <2e7b480a-ee84-4105-a3e4-b9297e4d9835@googlegroups.com>

Show all headers | View raw


Peng Liu (liupengwyy@gmail.com) writes:
> My C++ code accesses SQL Server by ODBC driver 2.x, 

That's a very old version. For connecting to SQL 2008, you should use
SQL Server Native Client 10.

> After my application starts? in SQL Server 2008 Managment Studio, run
> "DBCC OPENTRAN", no active open transaction is reported. And "select
> @@TRANCOUNT" return 0. 

But @@trancount is reported for the session in SSMS, so it says nothing
about your application.

If your application has an open transaction, you should see this with 
DBCC OPENTRAN - provided that you are in the right database.

> I am curious that which method is the exact one to get all the not-
> committed transactions.

When I run this on my machine:

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

The first query returns seven rows, while the second query returns no 
rows. Six of the seven rows in the first result set are related to 
replication that I have active in one database. The last comes from 
the SELECT statement itself. I note that all these transactions have
transaction_type = 2, that is they are read-only transactions.

As for your question, I think that the correct way is to join 
session_transactions with active_transactions and filter for the 
appropriate values. Or not filter at all, since I suspect that a value lie 
transaction_state = 6 ("The transaction has been committed") is very 
short-lived.

> What is difference between Open transaction and active transaction?

I'm not sure there is any. I would take them as synonyms.


-- 
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx

Back to comp.databases.ms-sqlserver | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

How to find not-committed transaction in SQL Server 2008 exactly? Peng Liu <liupengwyy@gmail.com> - 2013-04-27 00:11 -0700
  Re: How to find not-committed transaction in SQL Server 2008 exactly? Erland Sommarskog <esquel@sommarskog.se> - 2013-04-27 11:42 +0200
  Re: How to find not-committed transaction in SQL Server 2008 exactly? Peng Liu <liupengwyy@gmail.com> - 2013-04-27 19:57 -0700
    Re: How to find not-committed transaction in SQL Server 2008 exactly? Erland Sommarskog <esquel@sommarskog.se> - 2013-04-28 11:26 +0200
      Re: How to find not-committed transaction in SQL Server 2008 exactly? rja.carnegie@gmail.com - 2013-04-28 03:49 -0700
      Re: How to find not-committed transaction in SQL Server 2008 exactly? Peng Liu <liupengwyy@gmail.com> - 2013-05-05 20:35 -0700
        Re: How to find not-committed transaction in SQL Server 2008 exactly? Erland Sommarskog <esquel@sommarskog.se> - 2013-05-06 07:16 +0000
          Re: How to find not-committed transaction in SQL Server 2008 exactly? Peng Liu <liupengwyy@gmail.com> - 2013-05-06 18:40 -0700
            Re: How to find not-committed transaction in SQL Server 2008 exactly? Erland Sommarskog <esquel@sommarskog.se> - 2013-05-07 21:12 +0200
  Re: How to find not-committed transaction in SQL Server 2008 exactly? Peng Liu <liupengwyy@gmail.com> - 2013-04-28 00:52 -0700
  Re: How to find not-committed transaction in SQL Server 2008 exactly? Peng Liu <liupengwyy@gmail.com> - 2013-05-05 20:31 -0700
  Re: How to find not-committed transaction in SQL Server 2008 exactly? work4anvesh@gmail.com - 2015-08-26 10:47 -0700
  Re: How to find not-committed transaction in SQL Server 2008 exactly? work4anvesh@gmail.com - 2015-08-26 10:48 -0700

csiph-web