Link to home
Start Free TrialLog in
Avatar of Pooja Solanki
Pooja Solanki

asked on

out of string space error

i have changed an old  windows application made in VB to website in c#.Both are referring a same vb dll code.for that particular dll code, Both the applications show sometimes the out of string space error and we are fine with that. But the freqency of out of string space error is very high for website comparatively of windows application. This code generates a report. so it first write the data from database into an xml file and then generates a word file. while writing that xml,this error comes.
I have checked for the same object ,in windows application it took 6-7hours but finally it gives the report. While in website in around 1 hour it gives out of string space error.
What cold be the reason ?
ASKER CERTIFIED SOLUTION
Avatar of Dirk Strauss
Dirk Strauss
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
if you're doing a lot of string concatonations, then you'll get this error as you near running out of memory. Might I suggest a custom StringBuilder class to help minimize the errors.

Private Function CreateHtml( _
    ByVal sTitle As String, _
    lstDocuments As ListBox _
    ) As String

Dim i As Long
Dim buf As New cStringBuilder
   
   buf.Append("<HTML><HEAD><TITLE>")
   buf.Append(sTitle)
   buf.Append("</TITLE></HEAD><BODY>")

   buf.Append("<H1>")
   buf.Append(sTitle)
   buf.Append("</H1>")

   buf.Append("<TABLE><TR><TD>Document Id</TD><TD>Name</TD></TR>")   

   For i = 0 to lstDocuments.ListCount - 1
     buf.Append("<TR><TD>")
     buf.AppendByVal(lstDocuments.ItemData(i))
     buf.Append("</TD><TD>")
     buf.Append(lstDocuments.List(i))
     buf.Append("</TD></TR>")
   Next i      

   buf.Append("</TABLE></BODY></HTML>")   

   CreateHtml = buf.ToString
End Function

Open in new window

Avatar of Pooja Solanki
Pooja Solanki

ASKER

i just want to know why is the same code behaving differently in windows application and web application?
for a same object ,In windows it is generating the report in 6 hours  but in website it is giving the out of string error in around 1 hour?.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
reason might be inside that dll you mention, string concatenation in loops is a common memory hog, depending on how are you building your xml file, try to do it in smaller chunks, by line, it would be better if you show us that part of code that does the string manipulation so we can give you proper advice.
 
Also server migth have concurrent users or other apps/processes running, eating more memory than your windows app.
i have optimized the website by writing a new code that directly take data from db one by one and write to xml,it just generates the report in seconds for even large datas. But i am supposed to give the reason why is it giving that error in the report for website i have made with the same code funtionality  and generating the report in windows application for the same object.
Note: At times we have seen this string out of space error even in the windows application . But in this particular case, why is the report generating in the windows application and giving the error in website . Or why is the error more frequent in website ?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
helped a lot.Thanks:)