
		    Preventing Simultaneous Access
			   To Network Files


	Most networks are installed because a company decides
	that the ability to share files will benefit the business,
	and with many applications this is true.  However, there
	are instances where simultaneous access to a data file is
	neither necessary nor desireable (e.g., no one must be allowed 
	to add records to a sales file while invoices are being
	generated because the resulting bills may be incomplete).
	Most multi-user applications incorporate file-locking routines
	to prevent this.
	
	Single-user programs have no such safeguards, however, and
	annoying (if not disastrous) results can occur when two or
	more users attempt to use a single data file at the same time.
	Novell provides a couple of ways to restrict simultaneous access
	to files.  One method is to flag a file as Non-Shareable. 
	This has two drawbacks, though.  First, access will be limited
	to one user at all times, not just during file reorganization.
	Second, this method works only with programs that keep their
	data files open during use; many applications do not.
	A better alternative is to use the supervisor utilities HOLDON
	and HOLDOFF to lock out concurrent access.  When HOLDON is
	called before entering the program whose files must be locked,
	the network will keep open any files that the program uses
	and keep other users out.  HOLDOFF is then run upon leaving
	the application to restore shareability.

	Unfortunately, there are some programs that HOLDON does not
	work with.  Lotus 1-2-3 Release 2 is one.  I found that out 
	when our company decided to put the sales order log on-line
	by having the secretaries enter sales information into a 
	spreadsheet.  It appeared as though we would have to rely
	upon VoiceNet ("Anybody in the sales book?"  "Yeah, wait a
	sec...") until I remembered the IF EXIST batch file conditional
	provided by DOS.  The trick is to create a batch file that
	checks for the presence of a flag, in this case another file,
	before entering the spreadsheet.  If the flag file does not exist,
	it is created and then Lotus is run.  If the flag does exist,
	the batch file exits with a "Spreadsheet in use" message.

	Actually, merely exiting from the batch file is not a satis-
	factory answer either, since the secretary has wasted more
	time trying to get into Lotus than she would have if she had
	simply yelled out a question.  The solution I came up with
	used two public domain utilities, STACKEY and ASK, to set up a
	timing loop that waited for prior users to get out of the
	spreadsheet and then automatically ran Lotus.  The file
	appears below, generalized a bit and commented.

	If anybody has comments or improvements I would love to hear
	them.  Send me a message in the LAN conference of this board.

	John Manning




			      ORDER.BAT

	
rem **********************************************************************
rem
rem  Prevents more than one person from accessing the sales order book.
rem 		
rem			  Custom Software by
rem		      Infinite Resources, Ltd 
rem			      25 Apr 88
rem
rem **********************************************************************

ECHO OFF	REM The usual setup stuff
CLS						
G:
CD \LOTUS2

:START
		REM Does the file BUSY.FLG exist in the S:\ORDER directory?
		REM If so, go to the wait routine

IF EXIST S:\ORDER\BUSY.FLG GOTO MSG		

		REM If not, create the file

COPY S:\ORDER\IDLE.FLG S:\ORDER\BUSY.FLG

HOLDON		REM What the heck; can't hurt, eh?

		REM Stackey is used here to feed keystrokes to Lotus
		REM to bring up the spreadsheet automatically

STACKEY W10 "/FDS:\ORDER" CR W10 "/FR" W10 "ORDER.WK1" CR

123

HOLDOFF		REM Through with Lotus
		REM Delete the flag file 

DEL S:\ORDER\BUSY.FLG

		REM And quit

GOTO END


:MSG

BEEP		REM Optional - Norton's noisemaker

		REM Use ASK to see if the user wants to get in line

ASK The order book is in use.  Want to wait

		REM If not, quit

IF ERRORLEVEL 2 GOTO END

		REM The waiting game...

:LOOP

		REM Check to see if the previous user is still in the file
		REM If BUSY.FLG is gone, so is the user

IF NOT EXIST S:\ORDER\BUSY.FLG GOTO START

		REM If BUSY.FLG is here, hang out

CLS
ECHO Waiting for the order book to open...
ECHO (Press CTRL-C to quit)

		REM Wait five seconds before checking again

STACKEY {W=100}

		REM Check again
GOTO LOOP

:END

rem ********************************************************************


	A couple of notes:

	STACKEY is primarily a keystroke-stacking utility that allows
	one to feed setup commands to a program from a batch file
	instead of running the program and entering them from the 
	keyboard.  It is quite powerful and I highly recommend it.


	The version of ASK that I use is kind of flaky:  An "N" 
	answer returns an errorlevel of 2, and a "Y" returns
	something else (I don't know what; just check for IF
	NOT ERRORLEVEL 2 to branch on a positive).  I have included
	it in this archive.


	Don't use an unmodified loop for your wait routine:

		:LOOP
		IF NOT EXIST S:\ORDER\BUSY.FLG GOTO START
		ECHO Waiting...
		GOTO LOOP

	This will severely tie up the network.  Try it sometime
	and see (I got the code above to use 83% of the network
	resources all by itself!).
