简体   繁体   English

使用dataSet.GetXml()获取内存不足

[英]Get out of memory with dataSet.GetXml()

I've got error "System.OutOfMemoryException" if dataSet is too large and the memory is enough. 如果dataSet太大且内存足够,我有错误“System.OutOfMemoryException”。 The size of file "file1.xml" is about 36 MB. 文件“file1.xml”的大小约为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;
    }

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));
}

Try using dataset.ReadXml("MyFilename"); 尝试使用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. 我能够在具有4GB RAM的机器上读取250 MB的文件。

Edit: Try on a machine which has more RAM. 编辑:尝试具有更多RAM的计算机。

HTH HTH

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM