Windows Service, getting outOf memory exception

csharp , db Sweden
  • 12 years ago


     I'm managing an application that is using a Windows Service to handle request from application to the database. We have problems with OutOfMemory exception when trying to run bigger loads of data an also when trying to write bigger amount of data to files.

    This is the error message we get. 

    Error while delivering batch: System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown. at System.String.GetStringForStringBuilder(String value, Int32 startIndex, Int32 length, Int32 capacity) at System.Text.StringBuilder.GetNewString(String currentString, Int32 requiredLength) at System.Text.StringBuilder.Append(String value) at Eds.Emi.GeneralDelivery.BusinessLogic.XMLFormattingService.FormattingService.AppendContentMessages(String contractName, Products products) at Eds.Emi.BusinessLogic.ProductDelivererService.DeliverBatchProducts(Task task)


    The thing is that we can restart the service and try to run the same request from the application to the database, and it will work again. So it seems like something is not closed or cleaned out after a job is completed?? Anyone been having the same issues?




  • 12 years ago


    Generally  System.OutOfMemoryException is occurring when some of the object are used in application but not released after been used. So I think after releaseing all the unnecessary object after been used will help you out from this situation. Some of the tips for releaseing codeing sample..

     using(sqlDataAdapter da=new sqlDataAdapter() )


    //Write down your codeing

    on the above once the sqlDataAdapter has been used, it will realse from the memmory.

    Hope this will help you out. And if any miss information i have posted here, please share with me and help me to correct myself.



Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“It works on my machine.” - Anonymous