By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,168 Members | 2,548 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,168 IT Pros & Developers. It's quick & easy.

VB.NET Service and StreamWriter - File In Use Error

P: n/a
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
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.