The remote host closed the connection. The error code is 0x80070057

While creating a PDF or any file with asp.net pages I was getting following error.

Exception Type:System.Web.HttpException
The remote host closed the connection
. The error code is 0x80072746.
at System.Web.Hosting.ISAPIWorkerRequestInProcForIIS6.FlushCore(Byte[] status,
Byte[] header, Int32 keepConnected, Int32 totalBodySize, Int32 numBodyFragments, IntPtr[] bodyFragments, Int32[] bodyFragmentLengths, Int32 doneWithSession, Int32 finalStatus, Boolean& async)
at System.Web.Hosting.ISAPIWorkerRequest.FlushCachedResponse(Boolean isFinal)
at System.Web.Hosting.ISAPIWorkerRequest.FlushResponse(Boolean finalFlush)
at System.Web.HttpResponse.Flush(Boolean finalFlush)
at System.Web.HttpResponse.Flush()
at System.Web.UI.HttpResponseWrapper.System.Web.UI.IHttpResponse.Flush()
at System.Web.UI.PageRequestManager.RenderFormCallback(HtmlTextWriter writer,
Control containerControl)
at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection
children)
at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
at System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer)
at System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output)
at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer,
ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter
adapter)
at System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer)
at
System.Web.UI.HtmlFormWrapper.System.Web.UI.IHtmlForm.RenderControl(HtmlTextWriter
writer)
at System.Web.UI.PageRequestManager.RenderPageCallback(HtmlTextWriter writer,
Control pageControl)
at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection
children)
at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
at System.Web.UI.Page.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer,
ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter
adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,
Boolean includeStagesAfterAsyncPoint)
Exception Type:System.Web.HttpException
The remote host closed the connection. The error code is 0x80072746.
at System.Web.Hosting.ISAPIWorkerRequestInProcForIIS6.FlushCore(Byte[] status,

After searching and analyzing I have found that client was disconnected and still I am flushing the response which I am doing for creating PDF files from the stream.

To fix this kind of error we can use Response.IsClientConnected property to check whether client is connected or not and then we can flush and end response from client.

Here is the sample code to fix that problem.

 if (Response.IsClientConnected)
            {
                Response.Flush();
                Response.End();
            }

That’s it Hope this will help you..Stay tuned for more.. Till that Happy Programming!!

Technorati Tags: ,
Shout it
Published Wednesday, December 22, 2010 11:49 AM by Jalpesh P. Vadgama

Comments

# MS Visual Studio 2010 » Blog Archive » ???????????????? ????????????. 21.12.2010

Pingback from  MS Visual Studio 2010  » Blog Archive   » ???????????????? ????????????. 21.12.2010

# re: The remote host closed the connection. The error code is 0x80070057

Wednesday, October 12, 2011 6:52 PM by pc

what is the use of flushing data over a connection that is already dead!?

# re: The remote host closed the connection. The error code is 0x80070057

Wednesday, January 04, 2012 1:22 PM by Madhu

HI All,

Even i have same error message here the following error message i got

System.Web.HttpException: The remote host closed the connection. The error code is 0x80072746.

  at System.Web.Hosting.ISAPIWorkerRequestInProcForIIS6.FlushCore(Byte[] status, Byte[] header, Int32 keepConnected, Int32 totalBodySize,

Int32 numBodyFragments, IntPtr[] bodyFragments, Int32[] bodyFragmentLengths, Int32 doneWithSession, Int32 finalStatus, Boolean& async)

  at System.Web.Hosting.ISAPIWorkerRequest.FlushCachedResponse(Boolean isFinal)

  at System.Web.Hosting.ISAPIWorkerRequest.FlushResponse(Boolean finalFlush)

  at System.Web.HttpResponse.Flush(Boolean finalFlush)

  at System.Web.HttpResponse.Flush()

  at OneEapp.OneEApp.Web.APP_showFaxDoc.Page_Load(Object sender, EventArgs e) in d:\SharedServices\APP\showFaxDoc.aspx.cs:line 99

  at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)

  at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)

  at System.Web.UI.Control.OnLoad(EventArgs e)

  at System.Web.UI.Control.LoadRecursive()

  at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

----------------------------------------------------------------

Below the code behind

if (Params.Trim() == "PREMIUM")

           {

               string newFile = @"D:\webapplications\TempPDF\Premium_Assistance_EN.pdf";

               System.IO.FileStream inPdf;

               byte[] binaryData;

               inPdf = new System.IO.FileStream(newFile, System.IO.FileMode.Open, System.IO.FileAccess.Read);

               binaryData = new Byte[inPdf.Length];

               long bytesRead = inPdf.Read(binaryData, 0, (int)inPdf.Length);

               inPdf.Close();

               ms = new System.IO.MemoryStream(binaryData);

           }

           else

           {

               ms = rProxy.ShowFaxDoc(Session["CountyName"].ToString().Trim(), Params.ToString().Trim());

           }

           if (ms != null)

           {

               Response.Clear();

               Response.ContentType = "application/pdf";

               Response.AddHeader("content-length",

                   System.Convert.ToString(ms.Length));

               Response.BinaryWrite(ms.ToArray());

               Response.Flush();

               Response.End();

           }

Please help me to fix this error or Where can i place this fix here...

# re: The remote host closed the connection. The error code is 0x80070057

Saturday, January 07, 2012 5:12 AM by Jalpesh P. Vadgama

@Madhu- Can you send me whole application if possible.