tags:

views:

577

answers:

3

I've got error "System.OutOfMemoryException" if dataSet is too large and the memory is enough. The size of file "file1.xml" is about 36 MB.

What is the way to solve this problem? Thanks in advance.

private XPathDocument GetXML(DataSet ds)
    {
        ds.WriteXml("file1.xml");
        ds.WriteXmlSchema("file1.xsd");

        XPathDocument doc = new XPathDocument(new StringReader(ds.GetXml()));

        return doc;
    }
A: 

Is it throwing in ds.GetXml or the StringReader constructor?

You could try this approach it might be a bit less sensitive.

private XPathDocument GetXML(DataSet ds)
{
    ds.WriteXml("file1.xml");
    ds.WriteXmlSchema("file1.xsd");
    XmlDocument doc = new XmlDocument();
    doc.Load("file1.xml");

    return new XPathDocument(new XmlNodeReader(doc));
}
John Hunter
A: 

Yes, it's throwing in StringReader constructor. I still get an error. It maybe better if I split up file.

Vorleak Chy
A: 

Try using dataset.ReadXml("MyFilename");

This has worked for me. I was able to read a file for 250 MB on a machine which has 4GB RAM.

Edit: Try on a machine which has more RAM.

HTH

Gokul