I need to export all datatables to individual XML files and I cannot export all the rows at once because of System.OutOfMemoryException if there is a huge table. So I tried to export N rows. However WriteXml throws an exception if I use paging syntax in query.
I've tested both queries in LINQPad, they are ok.
System.InvalidOperationException: Cannot serialize the DataTable. DataTable name is not set.
// The first query causes exception
string oraQueryGetTableData = "SELECT * FROM (SELECT t0.* FROM MY_TABLE t0) WHERE ROWNUM <= 100";
// The second query runs without any error
//oraQueryGetTableData = "SELECT * FROM MY_TABLE";
OracleCommand oraCommandGetTableData = new OracleCommand(oraQueryGetTableData, oraConnection);
OracleDataReader oraReaderTableData = oraCommandGetTableData.ExecuteReader();
DataTable dataTable = new DataTable();
dataTable.Load(oraReaderTableData);
// Exception might occur here
dataTable.WriteXml(writer, true);
What is the problem here or how can I fix this?
As the exception says - the table does not have it's TableName
property set. So you just need to set it.
DataTable dataTable = new DataTable { TableName = "MyTableName"};
dataTable.Load(oraReaderTableData);
....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With