Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL Connection handle Best practice
Message
De
28/03/2004 12:30:07
Suhas Hegde
Dental Surgeon
Sirsi, Inde
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00890192
Message ID:
00890260
Vues:
27
>>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
  ** handle error here whatever ..
  Rollback
 endif
else
 SQLExec(lnhandle, 'IF @@TRANCOUNT > 0 rollback' )
 Rollback
endif
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform