I have an API that I pull large datasets from (millions of records).
I am using XMLReader
thus:
XmlReaderSettings settings = new XmlReaderSettings();
settings.IgnoreWhitespace = true;
string xmldocstring = "";
using (XmlReader reader = XmlReader.Create(uri, settings))
{
reader.ReadStartElement("DATASET");
while (!reader.EOF)
{
if (reader.NodeType == XmlNodeType.Element)
{
try
{
XElement elR = XNode.ReadFrom(reader) as XElement;
//PROCESS XML AND DO WHATEVER WITH IT
}
catch (Exception ex)
{
Log.WriteLine(ex.Message);
Log.WriteLine(ex.StackTrace);
}
}
else
{
reader.Read();
}
}
}
It works most of the time. But if I get a record set that is over 1.5 million records, I CONSISTENTLY get the following error, which is recorded in my log (recorded by the catch in the code above).
Error Message:Unable to read data from the transport connection: The connection was closed.
Stack trace: at System.Net.ConnectStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Xml.XmlRegisteredNonCachedStream.Read(Byte[] buffer, Int32 offset, Int32 count)
at System.Xml.XmlTextReaderImpl.ReadData()
at System.Xml.XmlTextReaderImpl.ParseText(Int32& startPos, Int32& endPos, Int32& outOrChars)
at System.Xml.XmlTextReaderImpl.ParseText()
at System.Xml.XmlTextReaderImpl.ParseElementContent()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlReader.ReadStartElement(String name)
at My_Files.DataBuilder.GetDataFromAPI(Dictionary`2 pData, String uri, String type, String siteid, String mlid, String mid, DateTime start, DateTime end)
at My_Files.DataBuilder.GetTransactionData(Dictionary`2 pData, String type, String siteID, String mlid, String mid, String apiurl, String apipass, DateTime start, DateTime end)
at My_Files.Program.GetAndProcessData(String transactionFile, Dictionary
2 pData, String siteid, String mlid, List
1 dmids, DateTime dStartDate, DateTime dEndDate)at My_Files.Program.Run()
What is going on? What can I do to pull large data sets of xml data?