Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data Session

Status
Not open for further replies.

alisaif

ISP
Apr 6, 2013
418
AE
Hi

In data entry form I do not open tables in Data Environment I use at the time of replacing the records and using Select SQL to display query and soon after I close it. Is it good practice? If yes, what should I select in Data Session of form 1. Default data session or 2.Private Data Session.

Thanks

Saif
 
No, there's no reason to be opening and closing tables in the middle of form. Presumably,
your form needs to display data from one or more tables. You should either put them in the Data Environment or open what you need in the form's Load method.

In VFP, there's also no reason to use a query to collect data to display and then update tables with REPLACE. Data buffering gives you a much easier way to let users work and then choose whether to save or discard changes.

Tamar
 
Even if you query data and close it as soon as possible, every data access, every table of both the dataenvironment or used later or queried into a cursor, uses a workarea in the datasession. There is no reason to avoid that.

There is an easy choice for the datasession of forms: Always private data session. There are cases continuing in the current datasession makes sense, but in the normal case it makes more sense to have every form work in it's own datasession, to let it encapsulate not only a set of UI controls, but also restart a new datasession. To let a form work on eg the same record, pass in an ID, reopen the table, seek that id, or pass in a record object you SCATTER NAME before calling a form.

Working on the same table, eg in a list and a single record form, doesn't change that. Working on the same tables and records and not needing N separate forms, but 1:1, you rather extend the form or use pageframes instead of starting a separate form in the same datasession.

Using the same datasession in conjunction with CloseAll in the DE can hurt, in general working in the same datasession can cause more troubles than benefits.

Bye, Olaf.
 
Thanks for the reply!

If I call another form and using the same tables what data session should I choose, 1 or 2 for 2nd form. And, I use close tables syntax in destroy event of all forms, so when I close the 2nd form will it close the tables for the 1st form.

Saif
 
You don't use a synta, what do you mean by that.

It should already be clear, but I can also repeat:
Even if you use the same tables in a secondary form, you most often will not want to reuse the already started datasession, because you would want the possibility to start a form many times and work on different. It is not much overhead to reopen tables, you can reuse the same code and reuse the same tables (shared of coure) and work with the same alias names, as you have a new datasession. And closing all tables, closes just this session and does not cause form1 to lose it's controlsources.

So the rule of thumb really is, use private datasessions. Design your forms to always start from an empty datasession, and you have no problems with unwanted side effect. The AutoCloseTable property of a dataenvironment is .T. by default, which means closing a form closes all tables, but also cursors/query results/views etc. of the current datasession, and not only the ones opened or created by this form or this dataenvironment. There use private datasessions.

Bye, Olaf.
 
I just want to add that there's rarely a reason to use CLOSE TABLES ALL in code. If you're using private data sessions, tables are closed on the way out of the form.

Tamar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top