Hi, everyone
I have a multiple insert procedure something like below.
The data layer methods each create a connection, run a stored procedure(SQL Server) and close the connection.
Can anybody tell me if this will work and roll back when/if an error is found. I am worried that running the same procedure within a loop will stop it working ( I have never done any transactions before ).
Private sub InsertHeaderItems(strHeaderID,lngTimes as long)
Dim lng as Long
Dim ObjDataLayer as Object
Dim ctx as ObjectContext
set ctx = GetObjectContext
' Insert a header record on the Database
on error goto ErrorHandler
ctx.DisableCommit
Set ObjDataLayer = CreateObject("prjDL.DataLayer"
objDataLayer.InsertHeaderOnDatabase(strHeaderID,lngTimes)
For lng = 1 to lngTimes
' Insert an item record on the Database
objDataLayer.InsertItemOnDatabase(strHeaderID,lng)
Next
ctx.EnableCommit
ctx.SetComplete
Exit Sub
ErrorHandler:
ctx.SetAbort
End Sub
I have a multiple insert procedure something like below.
The data layer methods each create a connection, run a stored procedure(SQL Server) and close the connection.
Can anybody tell me if this will work and roll back when/if an error is found. I am worried that running the same procedure within a loop will stop it working ( I have never done any transactions before ).
Private sub InsertHeaderItems(strHeaderID,lngTimes as long)
Dim lng as Long
Dim ObjDataLayer as Object
Dim ctx as ObjectContext
set ctx = GetObjectContext
' Insert a header record on the Database
on error goto ErrorHandler
ctx.DisableCommit
Set ObjDataLayer = CreateObject("prjDL.DataLayer"
objDataLayer.InsertHeaderOnDatabase(strHeaderID,lngTimes)
For lng = 1 to lngTimes
' Insert an item record on the Database
objDataLayer.InsertItemOnDatabase(strHeaderID,lng)
Next
ctx.EnableCommit
ctx.SetComplete
Exit Sub
ErrorHandler:
ctx.SetAbort
End Sub