HighTechTalks DotNet Forums  

Asp keeps file handle after file close

ASP.net Web Services microsoft.public.dotnet.framework.aspnet.webservices


Discuss Asp keeps file handle after file close in the ASP.net Web Services forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
afg@calypsopublications.co.uk
 
Posts: n/a

Default Asp keeps file handle after file close - 12-10-2007 , 10:54 AM






I have written a vb.net web service (my first production service) which
recieves a dataset from a smart client and writes it to a file as xml on
aninternally visible server. The file is later picked up by a windows
service and processed. It all works fine apart from the fact that when the
windows service attempts to move the file to an archive location it
sometimes fails with the exception that the file is in use. I have checked
what process has the filehandle and it is aspnet_wp.exe, the asp process.
The file handle is not held for ever and it has been freed by the next day
and possibly sooned. It can also be freed by closing and restarting the
website, but this is not desirable or practical.

The relevant section of code is as follows

Dim xmlWrite As System.Xml.XmlWriter
Dim xmlSettings As New System.Xml.XmlWriterSettings
Dim xmlStream As New IO.FileStream(UseSales,
IO.FileMode.Create)
xmlSettings.Indent = True
xmlSettings.IndentChars = " "
xmlWrite = System.Xml.XmlWriter.Create(xmlStream,
xmlSettings)
Try
' write the transfer file
xmlStream = New IO.FileStream(UseSales,
IO.FileMode.Create)
xmlWrite =
System.Xml.XmlWriter.Create(xmlStream, xmlSettings)
SalesData.WriteXml(xmlWrite,
XmlWriteMode.WriteSchema)
xmlWrite.Flush()
xmlWrite.Close()
xmlWrite = Nothing
xmlStream.Close()
xmlStream.Dispose()
xmlStream = Nothing
Catch ex As Exception
ReturnVal = False
Me.LogResult(Serial,
TransferResults.WriteFailed)
If Diag = "T" Then
Me.LogMessage("XML Failed" &
ControlChars.CrLf & ex.ToString)
End If
End Try

The closing actions should be very much belt and braces but I was trying to
find a way to clear the file handle. They didn't work.

I think it is either a case that I am doing something wrong in the above
code (though i have similar code working in Winforms applications with no
problems) or else there are aspects of asp that I am not aware of.

Any assistance would be much appreciated.

Thanks in advance

Andrew

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.