When talking to SQL Server or Oracle you need to use
both transaction commands: VFP begin transaction plus SQL Server begin transacion. Likewise when closing it.
Below is an typical example on how to do it with SQL Server.
begin transaction
SQLExec( nConnection, ‘BEGIN TRANSACTION’ )
lEverythingOK = tableupdate( 2, .F., ‘rv_MyView’ )
if lEverythingOK
lEverythingOK = tableupdate( 2, .F., ‘rv_MyOtherView’ )
endif
If lEverythingOK
SQLExec( nConnection, ‘IF @@TRANCOUNT > 0 COMMIT’ )
end transaction
else
SQLExec( nConnection, ‘IF @@TRANCOUNT > 0 ROLLBACK’ )
rollback
Endif
You could use SQLCommit() or SQLRollback() instead of the SQLExec() that I am using here.
If you are subscribed to FoxTalk, take a look at issue September 2000 where I explained why you need to use both transaction commands.
>Hi all,
>
>I am wondering something. Up until now I’ve been sending my updates to the database with a TABLEUPDATE(.T.) everything has been fine. This is good if there is only 1 cursor to update. If I have several cursors to update that depend on each other. I don’t want 2 or 3 of them saved and the last one not. So I want to start using TRANSACTIONS set to 2. This means SQLCOMMIT().
>
>My question: If I go this route. Do I still send my updates in the same way? i.e. TABLEUPDATE(.T.)? And then after I am sure that every update when ok issue, the SQLCOMMIT? Or SQLROLLBACK if there was an error? Will the ROLLBACK clear all the previous TABLEUPDATEs?
>
>Also, I assume that I still need to set all my cursor properties as before.
>
>I am using a VFP database & ODBC driver. And VFP 6 SP3
>
>TIA
>Mike
Hector Correa