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!

Close open files on server... is it safe though?

Status
Not open for further replies.

EzLogic

Programmer
Aug 21, 2001
1,230
US
In my app, i do have a routine that checks for 'shutdown.txt' and will automatically make the app close etc..

however, sometimes, for whatever reason, we get a user where there couple files are open etc..

i saw this routine on "Sandstorm's blog"

Is it safe to "kill" open dbf files and dbc files?
how about data corruptions and index corruptions?

anyone used this technique? or something similar

Code:
 CREATE CURSOR junkopen (xID I, xuser c(10), xsystem c(10), xfiles c(100))


LOCAL oShell as wscript.shell, lcTempFile
lcTempFile = ADDBS(GETENV("TMP"))+SYS(3)+".txt"
oShell = createobject("WScript.Shell")

* create a CSV list of open files in server
oshell.Run("cmd /c openfiles /query /S < your server name > /U administrator /FO CSV /NH > "+m.lcTempFile,2,.T.)

* Clean it up, remove those warnings above the list
STRTOFILE(STREXTRACT(FILETOSTR(m.lcTempFile),"again.."),(m.lcTempFile))

* add records to our cursor
APPEND FROM (m.lcTempfile) TYPE CSV

* Clean it up
SELECT xfiles, xID FROM junkopen WHERE INLIST(UPPER(JUSTEXT(xfiles)),"DBF","CDX","APP","FPT") AND !EMPTY(JUSTEXT(xfiles)) INTO CURSOR junkopen

* Start closing remaining files on the list
SCAN
  WAIT WINDOW "Attempting to close "+ALLTRIM(junkopen.xfiles) NOWAIT
  oShell.Run("CMD /C OPENFILES /DISCONNECT /S < your server name > /ID "+TRANSFORM(junkopen.xID),2,.T.)
ENDSCAN

MESSAGEBOX("Target Open Files has been closed!")

* Perform your backup routine

Ali Koumaiha
TeknoSoft Inc.
Michigan
 
The only harm to be expected by disconnecting files from a server is corruption due to disconnecting at a moment changes are written to DBF files. If that disconnection is because a user left open an application, that mostly not the case. And if you try to get an exclusive hand of files because they are reported to be corrupt, you won't do further harm, would you.

Buffers are client side, so they just will get lost unsaved. Pessimistic locks are nothing else but normal file locks, and files also don't crash, if a clients crash having files open. Rather when the server crashes or more precise the hdd in a server crashes, file corruption is likely, but disconnecting files rather compares to lost LAN connection.

Like Tangunan I didn't know the openfiles command. Just trying it it right now it reports you have to activate the global "maintain objects list" system flag. (and also says openfile /? gives more info on that). It might be easy to set that up, but it's a prerequisite. What I know is a solution by Sergey Berezniker from and that has no further prerequisite, but it only shows the users, it doesn't disconnect the files. It should be possible once you know clients/users, though.

Both his and Jun Tangunan's solutions require elevated privileges. But that's a prerequisite quite impossible to overcome, I think. This is nothing a normal user should be able to do.

Bye, Olaf.
 
I have an app I wrote using VFP that I use on a regular basis to close files on servers. Not all my (or other programmer's) apps have any sort of automatic "kick out for maintenance" routine. And yes, a lot of times, apps are left open by a user who has gone home or to lunch and left when the need arises to use the tables exclusive.
I have had no issues with corruption closing files this way on the server, only when I have killed their app remotely before closing those files.
Anyway, if you're interested in the app I made, follow the link in my signature, then scroll down to "Open File lister". You can download the openfile.zip, extract it, and run the form from VFP. I included the project so you can make a .exe too if you want.
If the server doesn't have mapped drives, just enter the server name in the "Server" box and click the "Refresh List" button. You should see the open files.
As previously mentioned, you will need elevated privileges on that server to be able to close files though.


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top