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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multi user app problems… 5

Status
Not open for further replies.

Mandy_crw

Programmer
Jul 23, 2020
578
PH
I have done an app which is multi user and it was designed in multi user mode thru LAN… all tables are shared, i use flock and unlock commands… but there are times that when i use To display info using grid and cursor… the application in the other computer hangs.. and it continues when i close the app in the other computer… my question is, why, why does the app in the other computer stops or hangs. Please help me understand how multi use works, it is the locking of the table that causes the app to hang? Or there are other reasons? Please help… thanks in advance… godbles…
 
Mandy,

In general, if you lock a record or a file, and another instance of your program (or another program) tries to change that record or file in any way, then there is the possibility that the other instance will appear to hang. Whether or not that happens, and for how long it happens, depends on a number of factors, not least of which is the setting of SET REPROCESS. The whole thing is somewhat complicated, so I suggest that, before going any further, you have a careful reading of the SET REPROCESS Help topic.

For what it's worth, I usually set REPROCESS to a low number (typically about five). That tells the program to try to get a lock for that number of seconds. If the lock then fails, my error routine is triggered, and that displays a friendly message to tell user what is happening and advise them to try again later. This is the basis of so-called "pessimistic locking".

However, please don't simply copy my approach. Your requirements are probably quite different from mine, so what works for me might not be the best solution for you. The important thing is to understand how it all works (start by reading the Help topic mentioned above) before you go any further.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Ok Mike… thank you so much… i’ll try to read and research much about reprocess… thank you again Mike…
 
Hi myearwood, what is data modelling could you please explain further? Because my frustrations currently after doing and completing my app, is the hanging when the app is open in two computers via LAN. I am also reading and researching about reprocess…
 
If you want to edit records directly, it's a bad idea to FLOCK, which keeps other users out of the whole table. Better to RLOCK the record(s) you're working with.

Tamar
 
Ok tamar… but in the report generation is it ok to use flock()?
 
in the report generation is it ok to use flock()?

Generating a report only requires read-only access to the underlying table - it doesn't cause any data to change - so there is usually no need to use FLOCK() or RLOCK().

But you might be worried that another program or user is changing the data in the report's underlying table while the report is part way through printing. SET LOCK ON is designed to prevent that from happening.

But a more usual approach is to generate a cursor to drive the report. Since the cursor only exists in your application, there is no chance of anything else changing it, so locking isn't an issue.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
The report is essentially just a shot of the data as it was at that moment in time - it could be out of date in a few seconds !. So you don't want the data in the data source changing during report generation. Taking the cursor "snapshot" is ideal for reports.
 
Thank You Mike... Colin for your inputs... i am now in the process of testing whether the app will still freeze without flock and rlock... Im using cursor in generating my report... so far so good....

Thanks myearwood for explaining data modeling... is one very good example of primary key is the idnum?

Thanks eveyrone...
 
Mandy, sorry to be slow to answer. In general, the only time you should use FLOCK is when you're doing some kind of maintenance on your data where you need to keep all users out.

Tamar
 
Each table MUST have a meaningless key - often an integer, but I prefer sequential GUIDs.

I think that's what's known as a surrogate key?

I agree that meaningless keys are better than ones that have some significance to the user. Personally, I use Integer (Autoinc) for all my primary kes, and I do so in every table, including those that might never need a key. Integers have the advantage of only needing four bytes, compared to 16 for GUIDs, which could be significant in joins and filters where there are a lot of comparisons being performed. But GUIDs have advantages too.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I have two tables that both have idnum, i use idnum in relation to main table in retriving info in the second table... is this correct? can you give me an example in coding using primary key using two related tables? please help me more understand... thanks...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top