CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Transaction

  1. #1
    Join Date
    Aug 2001
    Location
    PA
    Posts
    150

    Transaction

    Hello,

    I am using the connection object to run action queries. Is there a property or method that could tell whether the connection has a transaction open or not?
    Thank You, Hisham

  2. #2
    Join Date
    Oct 2003
    Location
    Philadelphia, PA
    Posts
    167
    I would imagine that whatever connection object you're using woudl have a property telling you the status of the connection. If not, you coudl try polling the existance of the connection object itself as a way to derive its status. Good luck.
    Mike Dershowitz
    [email protected]
    www.lexientcorp.com

  3. #3
    Join Date
    Apr 2002
    Location
    Melbourne, Victoria, Australia
    Posts
    1,792
    If you're using sql server, you could write a proc that will return @@Trancount - if its not zero, then there is a transaction in progress, or waiting to be committed/rolled back
    Be nice to Harley riders...

  4. #4
    Join Date
    Apr 2002
    Location
    Sri Lanka
    Posts
    71

    Smile Try this...

    Hi,

    Code:
    if (adoConnnection.State = adStateOpen) then
         ' connection open for transaction
    else
         ' connection closed
    end if
    __________________
    - Buddhi from Sri Lanka -
    - Paradise of Sinhalese/Buddhists -

  5. #5
    Join Date
    Jan 2004
    Posts
    8
    You could try this too:

    --------------------------------------------------------------
    Dim blnOpen As Boolean
    Dim cnn As New ADODB.Connection
    'you must open the connection

    cnn.BeginTrans
    blnOpen = True

    'code

    cnn.CommitTrans
    blnOpen = False
    --------------------------------------------------------------

    You can use then blnOpen to find out the state of the connection.

  6. #6
    Join Date
    Apr 2002
    Location
    Melbourne, Victoria, Australia
    Posts
    1,792
    I think everyone else has missed the point - he is trying to determine whether a connection has a transaction that is currently open, not whether the connection is open or not.

    The only way to do that, is to call @@TranCount (in sql server), and whatever the equivalent is in other databases.

    If the connection is closed, then there can be no transactions outstanding, however if the connection is open, there may or may not be outstanding transactions, as the connection will not close if there are outstanding transactions, hence the question.
    Be nice to Harley riders...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured