I am not sure what 'buffermode override 5' is, & what your problem is, but before you pack the table you have to use it exclusively (use xyz excl) and it shouldnt be open by any other user.
Like Martin Said You can not pack a multiuser database when it is opened by oher people. My favorite trick is to run the application with SET DELETED ON then at night run a reindex routine that removes deleted records. I have a tables of tables to be reindexed at night and a routine that goes into a endless loop until the reindex is complete.<br>
<br>
Following is the code and the table structure.<br>
<br>
<br>
<br>
*/***************************************************************************<br>
*/Program : Sysindex<br>
*/System : Fox Library<br>
*/Purpose : Rebuild cdx files<br>
*/Syntax : do sysindex<br>
*/Returns : nothing<br>
*/Parameter : nothing<br>
*/Defaults : none<br>
*/Requires : nothing<br>
*/Changes : nothing<br>
*/Calls : nothing<br>
*/Version : 1.0<br>
*/Dated : 28 July 1997<br>
*/Written By: David W. Grewe<br>
*/***************************************************************************<br>
*& File Handling-Index<br>
*/***************************************************************************<br>
*/<br>
*/***************************************************************************<br>
*<br>
* Set enviroment<br>
*<br>
close data<br>
set exclusive on<br>
set deleted off<br>
set safety off<br>
set deleted off<br>
set talk off<br>
*set step on<br>
*<br>
* open the sysindex in directory you started up in BEFORE going to C: drive<br>
*<br>
? "Reseting Sysindex File"<br>
L_ERROR=0<br>
on error do TRAPERR<br>
use SYSINDEX alias SYSINDEX exclu<br>
if L_ERROR=0<br>
pack<br>
replace all completed with {}<br>
replace all avail with .t.<br>
endif<br>
use SYSINDEX alias SYSINDEX shared<br>
set filter to empty(completed)<br>
*<br>
* set default to c: drive there is a reason for this see diskspace() command<br>
*<br>
L_DEFAULTDIR = sys(5) + sys(2003)<br>
set default to c:\<br>
*<br>
* program memvars<br>
*<br>
C_CDXPRG = "C:\CDXPRG.PRG"<br>
C_CDXFXP = "C:\CDXPRG.FXP"<br>
L_ERROR = 0<br>
*<br>
* do forever until all records have a date in sysindex.completed field<br>
*<br>
do while .t.<br>
select SYSINDEX<br>
goto top<br>
do while !eof()<br>
*<br>
* tell user what is up and loop<br>
*<br>
L_PERCENT = str(((recno() / reccount()) * 100) , 6 , 2)<br>
L_MSG = "Percent Complete=" + alltrim(L_PERCENT)<br>
wait L_MSG window nowait<br>
clear<br>
*<br>
if SYSINDEX.NAME = "SYSINDEX"<br>
replace SYSINDEX.AVAIL with .T.<br>
replace SYSINDEX.COMPLETED with date()<br>
skip<br>
loop<br>
endif<br>
*<br>
if SYSINDEX.AVAIL = .f.<br>
skip<br>
loop<br>
endif<br>
*<br>
if !empty(SYSINDEX.COMPLETED)<br>
skip<br>
loop<br>
endif<br>
*<br>
* define loop memvars<br>
*<br>
replace SYSINDEX.AVAIL with .F.<br>
? "Working On " + alltrim(SYSINDEX.name)<br>
L_ERROR = 0<br>
L_TGTDBF = alltrim(SYSINDEX.WORKAREA) + alltrim(SYSINDEX.NAME) + ".DBF"<br>
L_TGTCDX = alltrim(SYSINDEX.WORKAREA) + alltrim(SYSINDEX.name) + ".CDX"<br>
L_TGTFPT = alltrim(SYSINDEX.WORKAREA) + alltrim(SYSINDEX.name) + ".FPT"<br>
L_SRCDBF = alltrim(SYSINDEX.DRIVE) + alltrim(SYSINDEX.directory) + alltrim(SYSINDEX.name) + ".DBF"<br>
L_SRCCDX = alltrim(SYSINDEX.DRIVE) + alltrim(SYSINDEX.directory) + alltrim(SYSINDEX.name) + ".CDX"<br>
L_SRCFPT = alltrim(SYSINDEX.DRIVE) + alltrim(SYSINDEX.directory) + alltrim(SYSINDEX.name) + ".FPT"<br>
*<br>
* set up the error trap<br>
*<br>
select 2<br>
on error do TRAPERR<br>
*<br>
* Will the file fit on the hard drive<br>
*<br>
L_handle = fopen(L_SRCDBF)<br>
L_Size = fseek(L_handle,0,2)<br>
= fclose(L_handle)<br>
*<br>
if file(L_SRCCDX)<br>
L_handle = fopen(L_SRCCDX)<br>
L_Size = L_Size + fseek(L_handle,0,2)<br>
= fclose(L_handle)<br>
endif<br>
if file(L_SRCFPT)<br>
L_handle = fopen(L_SRCFPT)<br>
L_Size = L_Size + fseek(L_handle,0,2)<br>
= fclose(L_handle)<br>
endif<br>
*<br>
if L_Size > diskspace()<br>
*<br>
* file will not fit<br>
*<br>
? "File Will Not File On Drive C:, Start the program on a computer With More Drive Space"<br>
use<br>
select SYSINDEX<br>
replace SYSINDEX.avail with .T.<br>
skip<br>
= inkey(2)<br>
loop<br>
endif<br>
*<br>
* file fits<br>
*<br>
use (L_SRCDBF) exclu<br>
on error<br>
*<br>
* if file is in use skip and got to next database<br>
*<br>
if L_ERROR = 1<br>
? "Can't Open File, Either It's: 1. Open, 2. Location Problem, 3. Corrupt"<br>
select SYSINDEX<br>
replace SYSINDEX.AVAIL with .t.<br>
skip<br>
= inkey(2)<br>
loop<br>
endif<br>
*<br>
* change enviroment<br>
*<br>
if SYSINDEX.pack = .T.<br>
set deleted on<br>
else<br>
set deleted off<br>
endif<br>
*<br>
* if there are no indexes on the file<br>
*<br>
if empty(SYSINDEX.CDXPRG)<br>
if SYSINDEX.pack<br>
? "No Index on File, Removing Deleted Records"<br>
pack<br>
else<br>
? "No Index on File, Pack Not Requested."<br>
endif<br>
use<br>
select SYSINDEX<br>
replace SYSINDEX.completed with date()<br>
skip<br>
? "Action Completed"<br>
? ""<br>
loop<br>
endif<br>
*<br>
if !empty(tag(1))<br>
set order to (tag(1))<br>
endif <br>
*<br>
* No one has the file open, copy to C drive to work on<br>
*<br>
? "Making A Backup Copy In Case Something Goes Wrong"<br>
set talk on<br>
copy to (L_TGTDBF)<br>
*<br>
select 3<br>
use (L_TGTDBF) exclu<br>
*<br>
* create a index file and reindex to file<br>
*<br>
? "Starting Reindex On Backup Copy"<br>
copy memo SYSINDEX.CDXPRG to (C_CDXPRG)<br>
set talk off<br>
comp (C_CDXPRG)<br>
wait clear<br>
set talk on<br>
do &C_CDXPRG<br>
set talk off<br>
select 3<br>
use<br>
*<br>
* move files back to their orginal location<br>
*<br>
? "Replacing Orginal File With Reindexed Backup Copy"<br>
select 2<br>
use<br>
delete file (L_SRCDBF)<br>
delete file (L_SRCCDX)<br>
delete file (L_SRCFPT)<br>
*<br>
set talk on<br>
if file(L_TGTFPT)<br>
copy file (L_TGTFPT) to (L_SRCFPT)<br>
endif<br>
if file(L_TGTCDX) <br>
copy file (L_TGTCDX) to (L_SRCCDX)<br>
endif<br>
copy file (L_TGTDBF) to (L_SRCDBF)<br>
set talk off<br>
if SYSINDEX.CLEANUP = .T.<br>
delete file (L_TGTDBF)<br>
delete file (L_TGTCDX)<br>
delete file (L_TGTFPT)<br>
endif<br>
delete file (C_CDXPRG)<br>
delete file (C_CDXFXP)<br>
*<br>
* update database<br>
*<br>
select SYSINDEX<br>
replace completed with date()<br>
skip<br>
<br>
enddo && (! eof sysindex)<br>
* && Reset enviroment<br>
wait clear<br>
set deleted on<br>
goto top<br>
if eof()<br>
exit<br>
endif<br>
wait window "Waiting 5 seconds for next loop"+chr(13) + "Ctrl+End to stop Loop" timeout 5<br>
if lastkey() = 23<br>
exit<br>
endif<br>
*<br>
enddo<br>
*<br>
set default to (L_DEFAULTDIR)<br>
clear<br>
return<br>
*<br>
*<br>
*<br>
procedure TRAPERR<br>
******************<br>
L_ERROR = 1<br>
= inkey(1.0)<br>
return<br>
<br>
<br>
<br>
<br>
Structure for table: D:\BIDSYS\DBF\SYSINDEX.DBF<br>
Number of data records: 96 <br>
Date of last update: 02/11/00<br>
Memo file block size: 64<br>
Code Page: 1252 <br>
Field Field Name Type Width Dec<br>
1 DRIVE Character 2<br>
2 DIRECTORY Character 25<br>
3 NAME Character 10 <br>
4 WORKAREA Character 25<br>
5 PACK Logical 1<br>
6 CLEANUP Logical 1<br>
7 AVAIL Logical 1<br>
8 COMPLETED Date 8<br>
9 CDXPRG Memo 4<br>
10 MAINTPRG Memo 4<br>
<br>
<br>
<br>
Sometimes it is necessary to do a little system maintenance. Sometimes the middle of the night just doesnt cut it. If you want to do and index and pack in your code, you should verify that you can use the tables exclusivly. <br>
Here is an example of such code.<br>
<br>
* Create an array of all tables in the database and scan them<br>
FOR i = 1 TO 3<br>
IF !EMPTY(latables<i>)<br>
ls_retry = "RETRY"<br>
ls_table = latables<i><br>
IF !lb_quit_program<br>
DO WHILE ls_retry = "RETRY"<br>
* If the file exists, check it by opening it<br>
IF FILE("data\"+ls_table+".dbf"<br>
* Open the next table<br>
IF used(ls_table)<br>
USE IN (ls_table)<br>
ENDIF<br>
USE (ls_table) IN 0 EXCL && set_buf_optimistic takes care of this<br>
IF !CURSORSETPROP("BUFFERING",1,ls_table)<br>
lb_quit_program = .T.<br>
EXIT<br>
ENDIF<br>
IF USED(ls_table)<br>
* If the table is used, it is ok. Close it and try the next table.<br>
USE IN (ls_table) && new ah 9/23<br>
USE<br>
ls_retry = "OK"<br>
ELSE<br>
* If the table is not used, it had a problem. If retry is false, do not continue.<br>
IF ls_retry = "QUIT"<br>
lb_quit_program = .T.<br>
ENDIF<br>
ENDIF<br>
ELSE<br>
* If the file does not exist, an update is needed<br>
WAIT window "no file found"<br>
gb_update_needed = .T.<br>
ls_retry = "OK"<br>
ENDIF<br>
ENDDO<br>
ON ERROR<br>
IF lb_quit_program<br>
EXIT<br>
ENDIF<br>
ENDIF<br>
ENDIF<br>
ENDFOR<br>
<br>
SET EXCLUSIVE OFF<br>
IF lb_quit_program<br>
=messagebox("Unable to gain sole access to tables, process aborted.",48+0,"exclusive access denied"<br>
ENDIF<br>
RETURN !lb_quit_program<br>
ENDFUNC
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.