Unable to read data from the transport connection

  • Thread starter Thread starter Greg
  • Start date Start date
G

Greg

Hi. This error is intermittent, and we can't figure out why it
happens. Otherwise, the request is successful, and we get the
response we expect. Here's the code (some variable declarations not
shown, but exist):

Dim sr As IO.StreamReader
Dim objResponse As Net.HttpWebResponse

Dim objRequest As Net.HttpWebRequest =
Net.WebRequest.Create(strURL)
objRequest.Method = "GET"
objResponse = objRequest.GetResponse()
sr = New IO.StreamReader(objResponse.GetResponseStream())
strXML = sr.ReadToEnd()
sr.Close()
sr = Nothing

strURL points to a server on our network (Intranet). Exception occurs
when sr.ReadToEnd() is called, and even when this happens,
objResponse.StatusCode and objResponse.StatusDescription are "200" and
"OK", respectively. And the streamreader always gets closed,
exception or not.

Thanks for any help.
 
In your code, you do not close the response object (objResponse). The
MSDN doc clearly states that you should close this to free resources
and to avoid trouble.
I had a similar issue in my code where the code worked fine but after
some calls to the function, I got weird behavior.
Just adding a simple objResponse.Close at the end of the function, made
my problems go away...

Jeroen van der Heijden
www.familyware.nl
 
Back
Top