We have a code which is extracting data from Oracle database. The data returned from the database is in XML format and it gets returned as ref cursor as it may contains multiple XML's. Each xml file size is about 5-7 MB, but when the file size goes above 25 MB we get exception thrown from the reader.
The exception thrown is - "System.AccessViolationException: Attempted to read or write protected memory."
The code on the C# side is a simple one - we extract data from the database as ref cursor and read the ref cursor using OracleReader. When we try to extract the xml into xmldocument using get reader this is the place where we get the System.AccessViolationException while trying to read the huge amount of data.
using (var cur= (OracleRefCursor)cmd.Parameters["cur_xml"].Value)
{
if (!cur.IsNull)
{
OracleDataReader rdr= cur.GetDataReader();
while (rdr.Read())
{
XmlDocument x = new XmlDocument();
x.LoadXml(rdr.GetString(0));//this line above throws the System.AccessViolationException
}
}
}
Any suggestion to fix this for large data.