?
Solved

Getting "underlying connection was closed..." error on HttpWebRequest()

Posted on 2009-05-08
2
Medium Priority
?
756 Views
Last Modified: 2013-12-17
We have a console application using HttpWebRequest on Win Server with .net 3.5. Intermittently, we get errors :

  The underlying connection was closed: An unexpected error occurred on a send. 

How can we correct this ?

Any advantage in adding ServicePointManager.MaxServicePoints and ServicePointManager.MaxServicePointIdleTime ?

Where would these be set  ?

Thank you,
Gary Davis
 
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(&.);
webReq.Method = "POST";
webReq.ContentType = "text/xml";
webReq.Headers.Add("Authorization", "Basic " + strAccount);
webReq.AuthenticationLevel = System.Net.Security.AuthenticationLevel.None;
webReq.KeepAlive = false;
 
HttpWebResponse webResp = (HttpWebResponse)webReq.GetResponse();
 
Stream stream = webResp.GetResponseStream() as Stream;
byte[] buffer = new byte[32 * 1024];
int nRead = 0;
MemoryStream ms = new MemoryStream();
 
do
{
 nRead = stream.Read(buffer, 0, buffer.Length);
 ms.Write(buffer, 0, nRead);
} while (nRead > 0);

Open in new window

0
Comment
Question by:Gary Davis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 11

Accepted Solution

by:
Muhammad Ousama Ghazali earned 1500 total points
ID: 24348255
The problem you are facing has been officially documented by Microsoft here: http://support.microsoft.com/default.aspx?scid=kb;EN-US;915599

For additional support, you may see this link too: http://weblogs.asp.net/jan/archive/2004/01/28/63771.aspx
0
 
LVL 18

Author Comment

by:Gary Davis
ID: 24400216
I have reviewed the sources and I am still seeing occasional issues so will try some different possibilities. I am closing this in any case.
Thanks
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question