Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
DataSession and Queries ran from an object???/
Message
From
10/06/2014 15:39:59
 
 
To
10/06/2014 10:31:10
General information
Forum:
Visual FoxPro
Category:
Object Oriented Programming
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
Visual FoxPro
Application:
Web
Miscellaneous
Thread ID:
01601560
Message ID:
01601597
Views:
42
>Here's what I'm finding...
>
>Any object in FoxPro that runs a query, whether against native DBFs or Sql Server, will create the cursor in the DataSession which was active at the time the object was created.
>
>The means that if you have a BO created in Form A with a Private DataSession, and you pass that object to Form B which has its own Private DataSession, if you use the object to run a query from Form B, the cursor will be created in the DataSession from Form A.
>
>Crazy! But true. It took be about an hour of stepping through the codez to figure this out.
>
>Does anyone know a work around, or a pattern to avoid this??

Actually, not so crazy. We had a related discussion here not long ago about object references. I think in your case the key thing to remember is that you're never passing the BO (i.e. by value), you're only ever passing a reference.

There only ever is one object, and as such it's logical to expect that anything you call on it to do will be within its own context.

Looking at it again I'm not sure what you're doing with the original BO. It looks like Form A has its own, private datasession. However, does the BO have its own private datasession or is it sharing Form A's?

One potential workaround would be to instanciate a new BO for Form B. You could consider basing the BO on the Session class, my understanding is it was specifically designed for this kind of scenario. If you need a copy of a BO maybe you could implement some kind of generic CloneBO utility method.
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Previous
Reply
Map
View

Click here to load this message in the networking platform