I've gotten into the habit of using:

USE mytable IN SELECT([mytable])

If it's not USED the SELECT() function returns the equivalent of the next 
available workarea. If the assumption is that you just want that table open, 
this eliminates any amibiguity. Of course as you've pointed out, if another 
user or process has an exclusive lock on the table, you'll still get some kind 
of file access error. Yes, there's some overhead to reopening the table but 
there's also overhead to checking to see if it is already in use, so as Uncle 
Ted would point out, you have to test that in your application environment to 
determine if that overhead is meaningful.

You can also wrap your USE statements in a TRY..CATCH and handle both error 3 
or 108 or any other file access specific error as appropriate.

--

rk
-----Original Message-----
From: ProfoxTech [mailto:[email protected]] On Behalf Of Ken Dibble
Sent: Thursday, July 16, 2015 9:21 AM
To: [email protected]
Subject: Re: "File In Use" on USE "during" SQL SELECT Execution


>A quick-and-dirty solution is to check USED("_table_name_") before 
>issuing any USE _table_name_! Here is an example:

Thank you. I always do that. In fact, my framework has a data manager class 
that handles this, so USE and SELECT are only issued in one place. If
USED() is .T., then I SELECT that work area.

However, I have also seen this before, rarely, in other situations:

IF NOT USED("mytable")
      USE mytable IN 0 && Error 3; File in use.
ENDIF

I kid you not. It's very strange.

I actually think there are processes in VFP that impose locks on tables that 
aren't always detected correctly. In the above case, it would seem that some 
OTHER user has the table open and locked for some purpose. The error reported 
should be 108, but sometime's it's 3.

I don't use USE AGAIN or ALIAS SomethingDifferent because it complicates the 
task of keeping track of what's been opened.

>You might also consider using USE...AGAIN ALIAS.... in all your SQL queries.

I don't use USE AGAIN or ALIAS SomethingDifferent because it complicates the 
task of keeping track of what's been opened.

> > Question 2: Insofar as possible, should I program defensively by 
> > disabling controls related to shutting down while queries are running?
>
>Why not use modal windows all the time so that users are always using 
>one window a time!

Most of my windows are modal, but sometimes people have to switch back and 
forth between two open windows to accomplish a task.

Thanks.

Ken 


[excessive quoting removed by server]

_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: 
http://leafe.com/archives/byMID/profox/bn4pr10mb0913a3e3a3f047f738c4c403d2...@bn4pr10mb0913.namprd10.prod.outlook.com
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to