>>You can use VFP transactions with SQL transactions, so you can rollback the VFP remote view if the SQL update fails. At that point, you're not actually rollingback any "real" data changes with the VFP transaction, but just whether the cursor thinks it's updated the back-end and the oldval() values.
>
>To expand on that, if you're updating multiple cursors, you really do need to tie together your tableupdates() and SQL transactions within a VFP transaction. Otherwise if you're updating multiple cursors and #3 fails, cursor #1 and #2 would be out of sync with SQL Server. Of course, with only one tableupdate(), this wouldn't be necessary since the one and only tableupdate would fail.
>
>So:
>SQLSETPROP(lnhandle,"Transactions",2) &&set to manual
>BEGIN TRANSACTION
>IF tableupdate() and tableupdate() and tableupdate()
> SQLCommit(lnhandle)
> END TRANSACTION
>else
> sqlrollback(lnhandle)
> ROLLBACK
>endif
Hi,
I am no expert on this but would modify the code further like this
Begin transaction
sqlexec(lnhandle,"begin transaction")
IF tableupdate() and tableupdate() and tableupdate()
lnupdate = SQLExec(lnhandle, 'IF @@TRANCOUNT > 0 COMMIT' )
if lnupdate = 1
end transaction
else
Rollback
endif
else
SQLExec(lnhandle, 'IF @@TRANCOUNT > 0 rollback' )
Rollback
endif