1

In C# i'm trying to get the xml string from a big DataSet:

private string GetXmlFromDecomposedPortfolio(string dataSetName, DecomposedPortfolio ptf)
{
     StringWriter writer = new StringWriter();

     System.Data.DataSet ds = new System.Data.DataSet(dataSetName);

     ds.Tables.Add(ptf.Security.Copy());   
     ds.WriteXml((TextWriter)writer, XmlWriteMode.IgnoreSchema);

     return writer.ToString();
}

but i've got the exception:

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(Char value)     at System.IO.StringWriter.Write(Char value)  
    at System.Xml.XmlTextWriter.WriteStartElement(String prefix, String localName, String ns)   
    at System.Data.DataTextWriter.WriteStartElement(String prefix, String localName, String ns)  
    at System.Data.XmlDataTreeWriter.XmlDataRowWriter(DataRow row, String encodedTableName)  
    at System.Data.XmlDataTreeWriter.Save(XmlWriter xw, Boolean writeSchema)    
    at System.Data.DataSet.WriteXml(XmlWriter writer, XmlWriteMode mode)   
    at System.Data.DataSet.WriteXml(TextWriter writer, XmlWriteMode mode)    
    at Decompose.Library.Render.GetXmlFromDecomposedPortfolio(String dataSetName, DecomposedPortfolio ptf)   
    at Decompose.Library.Render.SavePE()  
    at Decompose.Library.WorkFlow.ProcessBatch()

Any suggestion?

1

1 Answer 1

1

First you create huge (apparently) xml data

ds.WriteXml((TextWriter)writer, XmlWriteMode.IgnoreSchema);

After clone it, into the string object writer.ToString();, so you almost double the memory you need.

What you can do, is to create XML row-per-row, so create kind of XmlDataSetRowEnumerator, that retrieves XML-per-row and yield returns the resulting XML.

Sign up to request clarification or add additional context in comments.

1 Comment

And what about splitting the dataset in different ones?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.