I have a problem with ADO transaction. I would like to catch error that is thrown within db, not generic one.
If I remove transaction and execute command then I am able to get it in VBA using err.description. Something like “***** [example], Line 116. Error Number 2627: Violation of[…]
But If only I will wrap command within transaction I get just “The current transaction cannot be committed and cannot support operations that write to the log file. Roll back the transaction.”
I need to get internal error in vba and keep command within transaction.
Sub test()
On error goto errhandler
Set dbConnection = New ADODB.Connection
dbConnection.ConnectionTimeout = 15
dbConnection.CursorLocation = adUseServer 'adUseClient
connectionString = GetConnectionString(ConnectionTypes.ADO)
dbConnection.Open connectionString
dbConnection.BeginTrans
Dim exampleCMD As ADODB.Command
Set exampleCMD = New ADODB.Command
exampleCMD.ActiveConnection = dbConnection
exampleCMD.CommandTimeout = MAX_TIMEOUT
exampleCMD.CommandType = adCmdStoredProc
exampleCMD.CommandText = "example procedure"
With exampleCMD
.Parameters.Append .CreateParameter("@ReportingDateId", adInteger, adParamInput, 4, reportingDateID)
.Parameters.Append .CreateParameter("@UserName", adVarChar, adParamInput, 50, Null)
End With
exampleCMD Execute , , adExecuteNoRecords
dbConnection.CommitTrans
errhandler:
debug.print err.description
dbConnection.rollback
End sub
Lech Weglarski is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.