Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to Create a New Datasession
Message
De
21/03/2007 14:00:59
 
 
À
21/03/2007 13:51:20
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP1
Divers
Thread ID:
01206682
Message ID:
01206690
Vues:
25
This message has been marked as the solution to the initial question of the thread.
>I would like to create a new private datasession for a common module in order to isolate database changes this module will make from the calling module.

You can code the module as a class based on Session base class, then to use it just instantiate the class and call methods. Or you can store the value of SET("DATASESSION") to a var, instantiate a private-datasession object with
myObj = CREATEOBJECT("Session)
then
SET DATASESSION TO myObj.DataSessionID
and when done, set the datasession back to the original.

I much prefer the first approach of coding as a class based on Session because you don't have to explictly change the datasessions. The Session-based class starts up in a private session and that session goes away when the object is released. You can do ANY data commands inside that session (including CLOSE DATABASES, etc) without affecting anything outside the session.

However, you should be aware that some environment settings that are scoped to DataSession must be set in the Session's Init, so I usually have an AppSession subclass of Session with the proper stuff in the Init available to instantiate if I need to use the second approach above, and also to subclass from if using the first approach.
David Stevenson, MCSD, 2-time VFP MVP / St. Petersburg, FL USA / david@topstrategies.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform