.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

StreamWriter Error: Cannot close stream until all bytes are written.

Posted By:      Posted Date: September 02, 2010    Points: 0   Category :ASP.Net
 Hi, I have a testing platform that allows data to be posted to a real time collection system.  It uses the StreamWriter object to send both HTTP and XML formats, It works fine, but there is a new request to submit uploaded files.  This again works fine, unless the files are over 70k (we need to test upto 3MB).  If it is over 70k, the response is the content-length too big.   I have changed it so that the content-length is now set dynamically, dependant on the size of the file uploaded.  However, when the StreamWriter.Close() runs, the execption The request was aborted: The request was canceled. is generated, with the InnerException Cannot close stream until all bytes are written.From what I have found on the web, the solution is use StreamWriter.Flush(), but this code is already in place. Code is as follows:  With WebRequest .Method = "POST" .ContentType = "application/x-www-form-urlencoded" .PreAuthenticate = False .AuthenticationLevel = Security.AuthenticationLevel.None End With If FileSize > 0 Then WebRequest.ContentLength = FileSize End If Try RequestStream = WebRequest.GetRequestStream() StreamWriter = New StreamWriter(RequestStream) StreamWriter.Write(strDataToPost)

View Complete Post

More Related Resource Links

While trying to view a report in integrated mode i see an unsupported RPL stream error

Trying to deploy a report in integrated mode on MOSS 2007. SQL server version is 2008 R2. I see the following:   ??? ?????????? ? ????м???? ?? ??????? ????????? ??????. ?????????? ?????????????м?? ?????? ?????? RPL: 34.62.1836345404. ??????м?? ??????: 10.3.     Yes i know its in russian. Another fail of Microsoft not being able to see the error codes and strings in english language, makes finding solutions even harder, because first you must find HOW is this called in english, then look for solution. Okay so, i found out that it is actually transalted into: unsupported RPL stream version detected 34.62.1836345404 expected version 10.3 Now, everywhere around the webs they say that this is because my Add-in is out of date and i need new RS addin for MOSS 2007.  But the link is dead!    For example, here http://social.msdn.microsoft.com/Forums/en-US/sqlreportingservices/thread/61357765-52aa-4085-9ee0-4cb494a6c3ad   @For SQL 2008 R2 together with WSS 3.0 / MOSS 2007, you need the SQL server 2008 november CTP add in:  http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=44bda62c-0cda-4a99-8d0a-d7fe06b39422 But the link is dead and there is no hint as to what happened.   The only valid link i found is this: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=65606fdd-093f-4c

Incomplete/truncated data Serialized to disk. Error:End of Stream encountered before parsing was com

Greetings!! i have a dataset which is constantly serialized & deserialized by multiple threads (in a thread safe manner using lock statement) using System.Runtime.Serialization.Formatters.Binary.BinaryFormatter (.net 2.0). The Code below works pretty fine but in some rare scenarios it gives the above exception while deserializing. public void SerializeData(string path, DataSet currentData) { dataStream = new FileStream(path , FileMode.Create, FileAccess.ReadWrite); try { biFormatter.Serialize(dataStream, currentData); } finally { dataStream.Flush(); dataStream.Close(); } } DataSet DeserializeData(string path) { dataStream = new FileStream(path , FileMode.Open, FileAccess.ReadWrite); DataSet storedDataSet = new DataSet(); storedDataSet.Locale = CultureInfo.InvariantCulture; try { storedDataSet = (DataSet)biFormatter.Deserialize(dataStream); } finally { dataStream.Close(); } return storedDataSet; } When i observed the serialized file i realized the file had some in incomplete/truncated data. The truncated file loo

error: null is not valid value for stream


Dim strm As System.IO.Stream = Me.GetType().Assembly.GetManifestResourceStream("fullbuttonface.bmp")

_buttonFace = New Bitmap(strm)

May be the  bitmap file is not part of the assembly, how do I put it in the assembly


Error while reading message framing format at position 0 of stream (state: ReadingUpgradeRecord)


While calling a WCF service(service is hosted as a windows service) from a client application, below exception is being thrown:

System.ServiceModel.Security.MessageSecurityException: The server rejected the upgrade request. ---> System.ServiceModel.ProtocolException: Error while reading message framing format at position 0 of stream (state: ReadingUpgradeRecord) ---> System.IO.InvalidDataException: More data was expected, but EOF was reached.   --- End of inner exception stack trace ---   --- End of inner exception stack trace ---  Server stack trace:   at System.ServiceModel.Channels.ConnectionUpgradeHelper.ValidateUpgradeResponse(Byte[] buffer, Int32 count, ClientFramingDecoder decoder)   at System.ServiceModel.Channels.ConnectionUpgradeHelper.InitiateUpgrade(StreamUpgradeInitiator upgradeInitiator, IConnection& connection, ClientFramingDecoder decoder, IDefaultCommunicationTimeouts defaultTimeouts, TimeoutHelper& timeoutHelper)   at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.SendPreamble(IConnection connection, ArraySegment`1 preamble, TimeoutHelper& timeoutHelper)   at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.DuplexConnectionPoolHelper.AcceptPooledConnection(IConnection connection, TimeoutHelper& timeoutHelper)  

Custom File Stream Result error when the client connection is closed


I recently notice that on our MVC 2.0 web app that does images retrieval,  we have this error when the user close the browser before image file is done transmitting :

TypeName: System.Web.HttpException

TypeAssembly: System.Web, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

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

Source: System.Web

TargetSite: Void RaiseCommunicationError(Int32, Boolean)

StackTrace:    at System.Web.Hosting.IIS7WorkerRequest.RaiseCommunicationError(Int32 result, Boolean throwOnDisconnect)

   at System.Web.Hosting.IIS7WorkerRequest.ExplicitFlush()

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

   at System.Web.HttpResponse.End()

   at CT.iMagio2.Apps.Web.Search.Controllers.ControllerActionResultInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)

   at System.Web.Mvc.ControllerActionInvoker

Capturing the error for a query written in an Execute SQL task



I have a SSIS 2005 pkg with an execute SQL task and a query as a SQLstatement. I want to capture a possible error generated from this query. How can I do it? Using the Result set?


Incoming tabular data stream error

<!-- /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman"; mso-ansi-language:EN-GB;} @page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:35.4pt; mso-footer-margin:35.4pt; mso-paper-source:0;} div.Section1 {page:Section1;} -->

Hi I have an access database linked to a SQL 2008 back end, in the last few weeks I have start to get the following error when the users try to update a particular form.
ODBC--Update on Linked Table Bill Phonenum Add Failed.

[Microsoft][SQL Server Native Client 10.0][Sql Serer]The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Parameter 2 (""):data type 0X00 is unknown. (#8009)

I have searched for a fix for this but I can not find one, the error is inconsistent as it does not happen every time and seems to have moved, when it was first reported it was on a numeric field but it was reported yesterday on a bit field.
even more strange is the fact that if you go to the form change one bit field it does not happen, it

Error on Close


I'm getting an error whenever I close a form that I ran in debug mode on from VWD 2008.  The error says Microsoft JScript runtime error: Sys.InvalidOperationException: Handler was not added through the Sys.UI.DomEvent.addHandler method.

Can anyone tell me what is going on.  It happens every time and I have to click breaK and then stop debugging to get out.


Problem with WCF: Error while reading message framing format at position 13665 of stream (state: Rea



we're using the net.tcp binding, server is self-hosted.

One of our clients experience the following problem randomly appearing on each client couple of times a day:

System.ServiceModel.ProtocolException, System.ServiceModel, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089

Error while reading message framing format at position 13665 of stream (state: ReadingEnvelopeBytes)

The exception appears on the client. I analyzed the WCF trace of the server and there are no exceptions.

What can be the cause of the exception?

I'd really appreciate any help, because the client is in production and this brings lots of problems.


'TDS Protocol stream is not valid' error when running SQL Server 2008 with jdbc driver of version


I am using SQL Server 2008 on Windows Server 2008 R2 and one of our servers running as a windows service (on Windows Server 2008 R2) contacts the SQL Server 2008 in a timely fashion to get some information. During one of these runs, we encountered the following error logs in the service logs and thereby we took a hit in serving client requests. The jdbc jar that is used for database connectivity is of version 3.0 (sqljdbc.jar).


I can provide more details on this issue. Can someone please let us know why this can be occurring ? Just so you know, the set of errors repeats itself after sometime although on a different JDBC Connection (with different ConnectionID). We have a reconnection algorithm running in case the JDBC Connection is lost for some reason (but I would be surprised if this issue relates to the re-connect algorithm).


INFO   | jvm 1    | 2011/02/28 22:26:54 | Feb 28, 2011 10:26:54 PM com.microsoft.sqlserver.jdbc.TDSParser throwUnexpectedTokenException
INFO   | jvm 1    | 2011/02/28 22:26:54 | SEVERE: TDSReader@4686d ( ConnectionID:25 TransactionID:0x0000000000000000): FetchBufferTokenHandler: Encountered unexpected TDS_RET_STAT (0x79)
INFO   | jvm 1    | 2011/02/28 22:26:54 | Feb 28, 2011 10:26:54 PM com.microsoft.sqlserver.jdbc.TDSReade

Parameter is not valid. memory stream error


Hi,  I have these 2 functions that save an image using a stream, it works with small images (1kb) but not with large ones.

and i get the error:

Parameter is not valid.


Line 202: long len = ms.Length;

Line 203: byte[] b = new byte[len];

Line 204: using (System.Drawing.Image image = System.Drawing.Image.FromStream(ms))

 Line 205: {

Line 206: image.Save(Path.Combine(@"C:\Trash\", fileName));


        public static string writeImage(string imageLink)
            string fileName = getFileName(imageLink);
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(imageLink);
            HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

            using (Stream st = resp.GetResponseStream())

                MemoryStream ms = (MemoryStream)CopyStream(st);
                ms.Seek(0, SeekOrigin.Begin);
                long len = ms.Length;
                byte[] b = new byte[len];
                using (System.Drawing.Image image = System.Drawing.Image.FromStream(ms))

GridView control to show master-child or master-slave data, written in c#, asp.net

I previously made a master slave datagrid using Visual Studio 2003 .Net (original article) that would allow users to show data to clients using collapse and expand features. These features however did not carry over to gridview for many users. This tutorial will explaing how to create a collapsable/expandable gridview in frameworks 2.0 and higher

IsapiModule Error 500 Issue


I am about exhausted trying to figure out this error:

HTTP Error 500.0 - Internal Server Error

Description: The page cannot be displayed because an internal server error has occurred.

Error Code: 0x8007007b

Notification: ExecuteRequestHandler

Module: IsapiModule

Requested URL: http://localhost:80/ReportServer

Physical Path: c:\Program Files\Microsoft SQL Server\MSSQL.2\Reporting Services\ReportServer

When I enable Failed Request Tracing Rules and view the log output I am supposing that the actual problem is in the 2nd call where there are 2 backslashes before the actual filename in the specified path:


CALL_ISAPI_EXTENSION DllName="C:\Windows\Microsoft.NET\Framework\v2.0.50727\\aspnet_isapi.dll"


Handling 404 page not found with Error page



      How do i handle 404 page not found?

Inserting personal error message in ValidationSummary



I am creating a web form that requires a lot of validation. I use many of the validation control in asp.net already like RequiredFieldValidator and CompareValidator. 

My Problem: after my custom validation for the value entered return an error message, and I pressed enter key when the field is empty, my custom error message is overlapped by my ValidationSummary. 

Setting my custom error to visible = false on button click also does not seem to work as it requires for me to enter the value first.

This made me think, is there a way to insert my custom validation inside the ValidationSummary as an error message like for other validation control?

Thanks in advance

Sys.Net.WebServiceFailedException: The server method '' failed with the following error:



Let's say we have 2 time consuming functions, aaa and aaa1 inside a aspx page.

        public static string aaa(int i)
            return i.ToString();

        public static string aaa1(int i)
            return i.ToString();



        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
        <span id="displayspan"></span>
        <br />
        <input type="button" value=

Jscript error: Object does not support property or method


 Hi, i have little knowledge on javascript but i need to use this code get from somewhere for a jquery to work.

I face this "Jscript runtime error: Object does not support property or method" whenever im trying to run this page.

In my experience, im get this error msg 9 out of 10 times i use javascript in my system.

Im using Microsoft Visual web developer 2008, i wonder if this is related to my problem, i not sure there is anything i need to add as reference or update anything.

But anyway, in short, i just couldn't use javascript code when using this development tool because of this sort of error.

Anyway, it happen that last time i tried use the same type of jquery code in another project and it seems to work well without an error.

But now when im try to use it again in this recent project i created, it come out with this error and i have no idea how to solve it even look through google and this forum.

It doesn't really seems like its the code problem itself although im not sure, because any javascript code just couldn't work.

So below is my code that i need to use.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" ></script>
<script type="text/javascript" src=&quo
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend