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

file in use error, wait, try again..... 2

Status
Not open for further replies.

inteleserve

IS-IT--Management
Dec 13, 2002
75
US
The .prg file below is running over and over again on my cpu...(for hours)... anyways sometimes after lets say 4 or 5 hours the program halts and I get an error message at

select * from /u/server/dstore/data/mainapps.dbf where recordid = datetime into table /u/server/dstore/data/tempapps.dbf

The error message says "FILE IN USE"

How can I word this so it says on error(file in use, ) wait 1 second and try again......






******************************************
set talk off
set safety off
close all databases
use /u/server/dstore/data/mainapps.dbf
store chrtran (DTOC(date()) +time(), ':/','') to datetime
replace all recordid with datetime for recordid=" "
close all
wait "" timeout 1

select * from /u/server/dstore/data/mainapps.dbf where recordid = datetime into table /u/server/dstore/data/tempapps.dbf

close all
use /u/server/dstore/data/sendapps.dbf
append from /u/server/dstore/data/tempapps.dbf
close all
delete file /u/server/dstore/data/tempapps.dbf
*****************************************************

 
An ON Error handler should be able to take care of this for you. Add:
Code:
ON ERROR DO hand_err WITH ERROR(), MESSAGE(), MESSAGE(1), PROGRAM(), LINENO()
after "close all databases"
Then add another routine something like this:
Code:
PROCEDURE hand_err
PARAMETERS zerror, zcmess, zcmess1, zprog, znlineno
PRIVATE    zerror, zcmess, zcmess1, zprog, znlineno
PRIVATE llgood_resp

DO CASE
*CASE zerror = 1705                  && File opening problem (probably EXCLUSIVE)
*   DO staluser WITH "Can't Open File - Access Problem", ;
      '(Read/Only, LAN Rights, Exclusive, etc.)'
*   IF yesno(.F., 'Try Opening File Again ?')
*      SET CONSOLE OFF
*      RETRY
*   ENDIF
   
*CASE zerror = 108 OR zerror = 109   && File/record locking problem
*   DO staluser WITH IIF(zerror=108,'FILE','RECORD')+ ;
      ' is in Use','Program Will Now Retry'
*   SET CONSOLE OFF
*   RETRY
   
CASE zerror = 3 && File in use
   = INKEY(2,"MH") && wait two seconds
   RETRY
ENDCASE
CANCEL
Note: I left a couple other cases in, but commented out so you could see the possibilities.

You should probably add a global counter so that you don't loop waiting forever. Just intialize and reset it in your code, and check it and increment it in the error routine.

Note: This routine (or a variant of it) was originally developed in FP 1.0, but used all the way up into VFP 8.0. The routines staluser() and yesno() are essentially customized shells to MessageBox() in FPW/VFP and look-alike code for FPD.

Rick
 
Rick beat me to the punch.

As Rick suggests and as is suggested by dgrewe in thread182-6321, your issue has to do with not your own USE of the table (which is easy to handle), but primarily with other user's USE of the table.

With that in mind, you need to:
1. First ensure that your own workstation is not USE'ing the table.
IF USED('tempapps')
SELECT tempapps
USE
ENDIF

2. Next you need to ensure that others are not USE'ing the table by attempting to USE tempapps EXCLUSIVE

3. BUT before you make the Exclusive attempt, you need to set up Error Handling as suggested by Rick and dgrewe so that your application will not crash and, instead, it will Wait until the attempt is successful.

4. Then, if you can successfully USE the table EXCLUSIVE, you immediately close it and run your Query.

Good Luck,


JRB-Bldr
VisionQuest Consulting
Business Analyst & CIO Consulting Services
CIOServices@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top