Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can SQL and VFP transactions co-exist?
Message
 
 
To
16/04/2015 03:16:54
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01618504
Message ID:
01618530
Views:
52
>>When I have 2 or more cursors (CursorAdapter) that need to be updated, and the database can be either VFP or SQL, can the
>>Transactions co-exist. Mainly I want to be sure that the BEGIN TRANSACTION and END TRANSACTION will not have an adverse affect
>>when using SQL Server. Here is a simplified case:
>>
>>The variable lSqlServer is set to .T. for SQL and .F. for VFP
>>
>>
>>*-- There are two cursors (for the sake of demo) working in this procedure c_table1 and c_table2
>>
>>*-- This one is for VFP database
>>BEGIN TRANSACTION
>>
>>if lSqlServer
>>   *-- This one is for SQL Server database  
>>   nRetVal = SQLSETPROP( oApp.conn_handle, "transactions", 2) 
>>endif 
>>
>>
>>lok = tableupdate( 0, .T., c_table1 )
>>if !lOk
>>	aerror( aErrorInfo )
>>	*-- store error description is some properties
>>endif 
>>
>>if lok
>>   lok = tableupdate( 0, .T., c_table1 )
>>   if !lOk
>>	aerror( aErrorInfo )
>>	*-- store error description is some properties
>>   endif 
>>endif 
>>
>>*-- Roll back changes if one of the tableupdates fails
>>if !lOk
>>   *-- Roll back changes to the cursors
>>   ROLLBACK
>>   tablerevert(.T., c_table1 )
>>   tablerevert(.T., c_table2 )
>>
>>   if lSqlServer
>>      *-- Roll back changes to the SQL tables   
>>      SQLROLLBACK(oApp.conn_handle)
>>   endif
>>
>>else
>>   
>>   *-- Commit changes for VFP data
>>   END TRANSACTION
>>
>>   if lSqlServer
>>      *-- Commit changes for SQL Server database
>>      SQLCOMMIT ( oApp.conn_handle )
>>   endif
>>
>>endif
>>
>>
>>Do you see any problem(s) with above code?
>
>For the TRANSACTIONS part I don't see any obvious problem, but in code optimization, I do:
>
>
>*-- There are two cursors (for the sake of demo) working in this procedure c_table1 and c_table2
>
>*-- This one is for VFP database
>BEGIN TRANSACTION
>
>if lSqlServer
> *-- This one is for SQL Server database
> nRetVal = SQLSETPROP( oApp.conn_handle, "transactions", 2)
>endif
>
>lok = tableupdate( 0, .T., c_table1 ) AND tableupdate( 0, .T., c_table2 )
>
>if NOT lOk
> aerror( aErrorInfo )
> *-- store error description in some properties
>
> *-- Roll back changes to the cursors
> ROLLBACK
> tablerevert(.T., c_table1 )
> tablerevert(.T., c_table2 )
>
> if lSqlServer
> *-- Roll back changes to the SQL tables
> SQLROLLBACK( oApp.conn_handle )
> endif
>
>else
> *-- Commit changes for VFP data
> END TRANSACTION
>
> if lSqlServer
> *-- Commit changes for SQL Server database
> SQLCOMMIT ( oApp.conn_handle )
> endif
>endif
>
>
>You mention that you use CursorAdapters, you may need to set their UseTransactions property.
>
>From the help file:
>
>The CursorAdapter object relies on ADO and ODBC APIs to manage transactions. If you ignore API recommendations and send specific transaction commands directly to an ADO or ODBC backend, you may want to set the UseTransactions property to False (.F.) to prevent undesirable transaction interaction.
>
>
>Regards.-

I have never used "UseTransactions" property and I will check where and how to apply it. Thank you, Fernando.
"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
Previous
Reply
Map
View

Click here to load this message in the networking platform