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?
Printable View
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?
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.
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
Hi,
Code:if (adoConnnection.State = adStateOpen) then
' connection open for transaction
else
' connection closed
end if
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.
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.