#139791 - 2005-05-16 08:51 PM
FYI -- File locking woes for noobies (like me)
|
thepip3r
Hey THIS is FUN
   
Registered: 2005-03-02
Posts: 350
|
If any of this is incorrect or incomplete, please correct me or add the information so others may see.
In working on my current project involving KiX, I've been working with the forum on good coding practices for writing error logs to a network file location. In this endeavor, I've come across a peculiar problem; Windows appeared to be "locking" files when multiple people were writing to the same file at once.
In my case, when a user logs onto the network, this script runs. If at any of the key points it fails, it writes an error log to a network share in the format of "current_date.xls". The information that was logged was the information contained in @ERROR and @SERROR along with the computer name, user, and time of the error. When I was writing the file to .doc's and .xls files, I'd have massive extra log files in my directory outside of the current date. It seems that when using any office extension to write your log file, Windows locks the file while it's in use so no one else can write to it.
So... in playing around with different formats, it appears this problem only pertains to file extensions where that extension is configured to open up with an Office Suite program. If you use an extension like .log or .txt, one that is not commonly opened by Office apps, your log file should work fine. I'm using .log and have yet to get an extra file to appear.
|
|
Top
|
|
|
|
#139792 - 2005-05-16 09:01 PM
Re: FYI -- File locking woes for noobies (like me)
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
There have been serveral threads that cover this topic. My solution is write a log file for each computer name then collect and consolidate the data.
|
|
Top
|
|
|
|
#139793 - 2005-05-16 09:07 PM
Re: FYI -- File locking woes for noobies (like me)
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
|
|
Top
|
|
|
|
#139795 - 2005-05-16 09:36 PM
Re: FYI -- File locking woes for noobies (like me)
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
I really do not think that the file extensions has much to do with file contention. There are 35,000 computers here that do cause file contention during the peak logon hours. The individual log files which are picked up and written to an Oracle DB works fine for me. Once written, I haven't touched it in years.
|
|
Top
|
|
|
|
#139798 - 2005-05-16 10:14 PM
Re: FYI -- File locking woes for noobies (like me)
|
Chris S.
MM club member
   
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
You can still run into file contention with text files. Run this script on two different computers at the same time...
Code:
Break On
IF Open( 3 , "\\someserver\someshare\TEMP\LOG.TXT" , 5 ) = 0 Do $x = WriteLine( 3 , @WKSTA + ": " + @TIME + @CRLF ) Sleep 1 Until @ERROR ELSE BEEP ? "failed to open file, error code : [" + @ERROR + "]" ENDIF
|
|
Top
|
|
|
|
#139802 - 2005-05-16 11:43 PM
Re: FYI -- File locking woes for noobies (like me)
|
thepip3r
Hey THIS is FUN
   
Registered: 2005-03-02
Posts: 350
|
well it's the same code I was asking about the other day:
Code:
function ErrorLog($ErrorMsg) DIM $LogFile,$LogError,$AltLogFile,$error,$serror,$ErrorString
$error = @ERROR $serror = @SERROR $ErrorString = "@WKSTA,@USERID,@DATE,@TIME,$error,$serror,$ErrorMsg,@CRLF" $LogFile = "\\server\SoftwarePushes\sms\logging\@Year_@MonthNo_@MDayNo.xls" $AltLogFile = "\\server\SoftwarePushes\sms\logging\@Year_@MonthNo_@MDayNo-@WKSTA.xls" $LogError = OPEN (5,$LogFile,5)
If $LogError=0 $ = WRITELINE(5,$ErrorString) $ = CLOSE(5) Else $ = OPEN (6,$AltLogFile,5) $ = WRITELINE(6,$ErrorString) $ = CLOSE (6) EndIf endfunction
Edited by thepip3r (2005-05-16 11:47 PM)
|
|
Top
|
|
|
|
#139803 - 2005-05-16 11:48 PM
Re: FYI -- File locking woes for noobies (like me)
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
How can you do a WRITELINE to an EXCEL file? Excel is not a raw text file.
Kent
|
|
Top
|
|
|
|
#139805 - 2005-05-17 12:05 AM
Re: FYI -- File locking woes for noobies (like me)
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
CSV is a text file. EXCEL (.XLS) is usually generated by EXCEL and is a binary.
You should be careful just changing file extensions around if you are not sure what they are.
WRITELINE/READLINE will work in the CSV file.
Kent
|
|
Top
|
|
|
|
#139809 - 2005-05-17 12:45 AM
Re: FYI -- File locking woes for noobies (like me)
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
You may also look into the use of WRITELOG() or WRITELOG2() UDFs which attempt to address file locking.
Kent
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 429 anonymous users online.
|
|
|