468,301 Members | 1,459 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,301 developers. It's quick & easy.

VB.NET Service and StreamWriter - File In Use Error

I'm writing a service in VB.NET. Reference the following code:

Dim oStreamWriter As StreamWriter
....
....
....
oStreamWriter = File.CreateText(TempLogFile)
If Err.Number <> 0 Then
EventLog.WriteEntry("LogService", "Error Creating Log File: " & _
TempLogFile & vbCrLf & _
"Error Code: " & Err.Number.ToString & vbCrLf & _
"Description: " & Err.Description.ToString, & _
EventLogEntryType.Error, 1004)
EventLog.WriteEntry("LogService", "Service Terminating", & _
EventLogEntryType.Error, 1004)
End
End If
oStreamWriter.WriteLine(buffer)
If Err.Number <> 0 Then
EventLog.WriteEntry("LogService", "Error Writing Log File Header
Row: " & _
ThisLogFile & vbCrLf & _
"Error Code: " & Err.Number.ToString & vbCrLf & _
"Description: " & Err.Description.ToString, & _
EventLogEntryType.Error, 1005)
EventLog.WriteEntry("LogService", "Service Terminating", & _
EventLogEntryType.Error, 1005)
End
End If
buffer = ""
--------------------------------------------------------------
Event Log Data Follows:
Event ID: 1004
Error Creating Log File: C:\WINNT\Temp\20040714_Security.log
Error Code: 57
Description: The process cannot access the file
"C:\WINNT\Temp\20040714_Security.log" because it is being used by
another process.
--------------------------------------------------------------

I've configured the Virus scanning to not scan C:\WINNT\Temp thinking
this was causing the issue, but was not. The Event ID traces to the
error check right after File.CreateText. The file does get create (0
byte file) in the folder specified. Service is configured to run as
an identity currently with Local Admin rights also. When testing on
Windows XP development box, works fine. Testing on W2K Server results
in the above error.

Using: MDE 2003 Version 7.1.3008
.NET Framework 1.1 Version 1.1.4322
Nov 20 '05 #1
0 1775

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by NPC403 | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.