I am trying to dump for XML a very large database (many gigabytes). I am using Linq-to-SQL to retrieve data from a database and Linq-to-XML to generate XML. I use XStreamingElementto keep memory low. However, the job still allocates all available memory before flipping over without writing any XML. The structure is as follows:
var foo =
new XStreamingElement("contracts",
<LinqtoSQL which fetches data>.Select(d =>
new XElement("contract",
... generate attributes etc...
using (StreamWriter sw = new StreamWriter("contracts.xml"))
{
using (XmlWriter xw = XmlWriter.Create(sw))
{
foo.WriteTo(xw);
}
}
I also tried saving with:
foo.Save("contracts.xml", SaveOptions.DisableFormatting);
... to no avail.
Any clues?
source
share