I have a windows service. It gets an XML form from an FTP server stores it in the local C: drive. It then takes the data and writes the content into a sql server database. Intermitently I get the following error.
Problems in loading file to read! System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.
at System.Net.HttpWebRequest.CheckFinalStatus()
at System.Net.HttpWebRequest.EndGetResponse(IAsyncRes ult asyncResult)
at System.Net.HttpWebRequest.GetResponse()
at System.Xml.XmlDownloadManager.GetNonFileStream(Uri uri, ICredentials credentials)
at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials)
at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn)
at System.Xml.Schema.DtdParser.ParseDocTypeDecl()
at System.Xml.Schema.DtdParser.Parse()
at System.Xml.XmlTextReader.ParseDtd(XmlScanner scanner)
at System.Xml.XmlTextReader.ParseTag()
at System.Xml.XmlTextReader.ParseRoot()
at System.Xml.XmlTextReader.Read()
at System.Xml.XmlValidatingReader.ReadWithCollectText Token()
at System.Xml.XmlValidatingReader.Read()
at System.Xml.XmlLoader.LoadCurrentNode()
at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc)
at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
at System.Xml.XmlDocument.Load(XmlReader reader)
at System.Xml.XmlDataDocument.Load(XmlReader reader)
at System.Xml.XmlDocument.Load(String filename)
at System.Xml.XmlDataDocument.Load(String filename)
at MyService.ParseXML.GetData(String filename) in C:\k\MyService\ParseXML.
vb:line 32
I am catching errors at various places. I know there is no problem in downloading the file. The error happens when the service tries to open the xml file to write it to the database.
I am also attaching some of my code.
Private Sub dowloadAndWriteIntoDatabase(ByVal time As String)
Call DeleteIfFileExists()
DownloadFile()
objWriteError.OnSuccess("Successfully completed download at " & time) //This is successful all the time
objParseXml.GetData("C:\temp\test.dat")
objWriteError.OnSuccess("Successfully entered into a database at " & time)
End Sub
Public Sub GetData(ByVal filename As String)
Dim objXml As XmlDocument = New XmlDataDocument
Try
objXml.Load(filename)
Catch ex As Exception
//This is the line that throws the error
objWriteError.onfailure("Problems in loading file to read! " & ex.ToString) End Try
Call GetNewsFeed(objXml)
End Sub
Can anyone please help me. It is driving me nuts and I have read a lot about it but I am not able to find a solution.
Thank You
Kal30