Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Will this Transaction work with SQL Server
Message
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Titre:
Will this Transaction work with SQL Server
Versions des environnements
Visual FoxPro:
VFP 9 SP1
Divers
Thread ID:
01537151
Message ID:
01537151
Vues:
84
Hi,

The following is just a draft of what I am planning to do when updating more than one table in SQL Server.
Will this approach work?
*-- oApp.conn_handle is the Connection Handle number obtained when application connects to the SQL Server.

nRetVal = SQLSETPROP( oApp.conn_handle, "transactions", 2) 

IF nRetVal < 0
    RETURN .F. 
ENDIF 

IF nRetVal > 0
     nRetVal = SQLEXEC( oApp.conn_handle, "Update MyTable1 SET MyField1 = '123' WHERE MyField1 = 'ABC"" )
ENDIF 

IF nRetVal > 0
    nRetVal = SQLEXEC( oApp.conn_handle, "Update MyTable2 SET MyField1 = '123' WHERE MyField1 = 'ABC"" )
ENDIF 

IF nRetVal < 0
    SQLROLLBACK(oApp.conn_handle)
ELSE 
    SQLCOMMIT(oApp.conn_handle)
ENDIF 

nRetVal = SQLSETPROP( oApp.conn_handle, "transactions", 1) 
Obviously I will add some error code to display if come across a problem. But my main question is whether setting SQLSETPROP "transaction" will work for the SQLEXEC() functions.
TIA.

UPDATE. My initial real coded test shows that the code above should work. The only thing I need is to figure how to make SQL Server fail to update one of the tables. So that I can see that Transaction really works. In VFP it would be easy; I would open a table EXCLUSIVE in another data session. But how would you suggest to do it in SQL Server?
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform