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

Updating a database structure, or packing, 'Who is still in the app'?

Status
Not open for further replies.

GriffMG

Programmer
Mar 4, 2002
6,333
FR
I have routines that update the database structure when there is a significant change in the applications version number, and sometimes it is difficult
to actually apply the update because users are in the system, but have forgotten, gone to lunch or whatever - so you can't get exclusive control to
make the changes.

Recently, in the last year or so, I have started adding a bit of code to the apps that helps me... When someone selects the database the application opens
a file in a USERS folder beneath the database folder - the app holds this open and never lets it go - it is simply a file called the users name using the
environment variable:

Code:
		ON ERROR DO FILEERR
		IF !DIRECTORY(m.DATALOCATION+"Users")
			MD (m.DATALOCATION+"Users")
		ENDIF
		m.USERHANDLE = FCREATE(m.DATALOCATION+"Users\"+DOS_FILE(GETENV("USERNAME")))
		ON ERROR DO USUAL WITH LINENO(),PROGRAM()

Then, when I need to know who to kick - I just try and delete all the files in the USERS folder and any I can't delete must be logged in:

Code:
	PRIVATE m.DATALOCATION,m.NUMUSERS,m.STRING
	m.DATALOCATION = TRIM(DTAFILES.PATH)
	m.STRING = ""
	IF !EMPTY(m.DATALOCATION)
		m.NUMUSERS = ADIR(ARYUSERS,m.DATALOCATION+"Users\*.*")
		FOR I = 1 TO m.NUMUSERS
			IF ARYUSERS(I,1) <> "."
				ON ERROR DO FILEERR
				DELETE FILE (m.DATALOCATION+"Users\"+ARYUSERS(I,1))
				IF MYFILE(m.DATALOCATION+"Users\"+ARYUSERS(I,1))
					m.STRING = m.STRING + ARYUSERS(I,1)+m.CRLF
				ENDIF
			ENDIF
		NEXT
		IF !EMPTY(m.STRING)
			MESSAGEBOX("The Following users are Logged in:"+m.CRLF+m.STRING,48,"Active Users")
		ELSE
			MESSAGEBOX("No Users are Logged in")
		ENDIF
	ENDIF

Not perfect, but functional

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
Looks good to me, Griff. The only small suggestion I would make is that you use local error trapping (TRY / CATCH / ENDTRY) rather than redirecting the ON ERROR. That would make it slightly more generic. But it doesn't affect the overall strategy.

In my own apps, I have a ForcedShutdown class which includes a timer which fires every few minutes. If a user is still logged in after the adminstrator has initiated the "kick out" function, the timer issues a warning, and then unceremoniously closes the user's copy of the app. I published the code for it in FoxPro Advisor a few years ago.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
I don't think I have ever used the Try.. Catch.. EndTry structure in VFP!

I just have two simple error handlers, FileErr() which is a 'ignore any error' one
and Usual() which is normally in place and handles anything else.

I have to use it (try.. catch.. finally) in C# - because otherwise the blessed language throws so many...

B-)

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
The reason I suggested local error-handling is that it would avoid the need to hard-code your ON ERROR:

Code:
ON ERROR DO USUAL WITH LINENO(),PROGRAM()

This isn't a problem for you, Griff, because you are only using this code in one application, and you know what the ON ERROR will contain. But that wouldn't be the case if you were publishing a gereric version of the code that would be usable in other apps.

Then again, you could always do it like this:

Code:
lcOldError = ON("ERROR")
ON ERROR DO FILERR
.... other stuff ...
ON ERROR &lcOldError

But as I said before, this is a small detail. It doesn't affect the overall strategy in any way.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
No, you are right Mike, although both the scheme above and the error handling are common to nearly all my apps - not just one, nearer to 80.

I was just trying to proffer the technique, rather than writing a FAQ with more generic code.

I'd never used that on() function before either - so that's two thoughts for the day!





Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top