A Wrapper Class for the SQL Server Based Data Access Helper - Adding wrappers for transactions
(Page 4 of 7 )
The following are the wrapper methods used to work with transaction-related commands:
PublicSub TransactionBegin()
arTransCommands = New ArrayList
End Sub
Public Sub TransactionAddCommand(ByVal SQLStatement As String)
arTransCommands.Add(SQLStatement)
End Sub
Public Sub TransactionRollback()
arTransCommands.Clear()
End Sub
Public Sub TransactionCommit()
Try
ObjLib = getDBHelperObject()
Dim b As Boolean = ObjLib.TransactionExecute(arTransCommands)
If Not b Then Throw New Exception("Transaction could not be performed -->Error logged.")
Catch ex As Exception
Throw ex
Finally
Try
System.EnterpriseServices.ServicedComponent.DisposeObject(ObjLib)
Catch ex As Exception
End Try
End Try
End Sub
To work with the above methods, you need to first start the transaction by simply calling the method “TransactionBegin.” You can add as many commands as possible by using “TransactionAddCommand.” After adding all the transaction commands, you simply execute all of them at the same time by issuing the “TransactionCommit” command.
Please note that I didn’t add any stored procedures to work with transactions.
Next: A Wrapper method to test whether a row exists >>
More MS SQL Server Articles
More By Jagadish Chaterjee