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

Checking if a table is available for exclusive use 1

Status
Not open for further replies.

StewartUK

Programmer
Feb 19, 2001
860
GB
Hi,

Part of a program that I run overnight is supposed to copy a dbf file from one network drive and overwrite the same file on the "live" drive.

This is sometimes failing because the table on the "live" drive is being held open by some user or other.

How can I check if a table is available to open exclusively - and is therefore overwriteable? I thought fopen() did this, but if another user has the table open it returns a correct handle, not -1.

Thanks for any help,

Stewart
 
Hi BurtanI,

No, I don't know that one. Can you tell me how it works or where I can look for other help?

Is it in the Win32API file?

Thanks for any further help you can give,

Stewart
 
Hi..
Instead of copying... can you think of using commands like the following..

Assumed you have created one set of all files in the backup directory and there is no new files (If this is wrong still similar idea can be used, but you have to modify the codes).

*********************************************************
PRG.. to back up my source data to a backup directory
*********************************************************
LOCAL aFiles, nCount, cBackDir, cSourceDir, I
DIMENSION aFiles(1,1)

** remember to add \ after the path correctly..
** example .... cBackDir = "C:\DATA\"
cBackDir = MyBackUpDirectory && put the value
cSourceDir = MySourceDirectory && put the value

nCount = ADIR(aFiles,cBackDir+"*.DBF")
I=1

** remember to set back these SETs later on suitably
SET TALK OFF
SET CONFIRM OFF
SET EXCLUSIVE ON

SELECT 0
FOR I = 1 TO nCount
WAIT WINDOW "Backing Up "+ ;
aFiles(I,1)+" ... Please wait" NOWAIT
USE cBackDir+(aFiles(I,1))
ZAP
APPEND FROM cSource+(aFiles(i,1)) FOR !DELETED()
WAIT CLEAR
USE
ENDFOR

SET EXCLUSIVE OFF && ETC SETS BACK TO YOUR VALUE
*********************************************************

The above does the complete appending of the records.. This could go on live even when others are in database.
Limitations..
1. Tend to become slow when others are holding record..
2. Not complete backup since.. imagine..
starting time hh hours...
appended first 5 files...
some used added 1 record on 6th file and one record on first file... The DBF set has the effects..(hope you understand). The same hold good,, even if in your above file locking method also... unless the entire directory is locked..
*********************************************
Hope the above idea is helpful.
ramani :-9
(Subramanian.G)
FoxAcc
ramani_g@yahoo.com
LET KNOW IF THIS HELPED. ENOUGH EXPERTS ARE HERE TO HELP YOU OUT! BEST OF LUCK :)
 
try

gnError = 0
on error do errortrap
select 0
use dbf2open exclu
if gnError > 0
do error ercovery
endif
on error && or reset you error trapping program.

procedure errortrap
gnError = error()
endproc
David W. Grewe
Dave@internationalbid.com
ICQ VFP ActiveList #46145644
 
Hi stewart,
I had the same problem. So, what i did, is instead of copying the DBFs, i used the foxpro command in the following way.
--------------------------------
******** NetToLcl.PRG ********

mError = 0

* set new error routine to ON ERROR
ON ERROR mError = ERROR()

* try to open the local file
USE myLocalDBF EXCLUSIVE

* if file opend successfully, mError will be Zero
IF mError <> 0
MESSAGEBOX ('Can Not process Now. Some users are Using the DBFs Exclusively')
RETURN
ELSE
* delete all the data of local dbf & then appen from remote
ZAP
APPEN FROM myNetworkTableWithFullPath
ENDIF

* set previous error routine to ON ERROR
ON ERROR myOriginalErrorRoutine
USE

-----------------

Hope it will move you in right direction.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top