Yvain Yvain - 3 years ago 182
C# Question

C# XmlSerialiser to Oracle Clob optimization

I go through many steps in order to save an xml file to an Oracle database.

XmlCustomType xmlCustomType = new XmlCustomType();

// feed xmlCustomType

var xmlSerializer = new XmlSerializer(typeof(XmlCustomType));

string xml;

using (StringWriter textWriter = new StringWriter())
{
xmlSerializer.Serialize(textWriter, xmlCustomType);
xml = textWriter.ToString();

using (var sr = new StringReader(xml))
{
char[] buffer = new char[1000];
int numChars;

using (OracleConnection con = new OracleConnection(""))
{
OracleClob clob = new OracleClob(con);

while ((numChars = sr.ReadBlock(buffer, 0, buffer.Length)) > 0)
{
clob.Write(buffer, 0, numChars);
}
}
}
}


I'd like to optimize this with something like

XmlCustomType xmlCustomType = new XmlCustomType();

// feed xmlCustomType

var xmlSerializer = new XmlSerializer(typeof(XmlCustomType));

using (OracleConnection con = new OracleConnection(""))
{
OracleClob clob = new OracleClob(con);
xmlSerializer.Serialize(clob, xmlCustomType);
}


Unfortunatly I Get this error message that I cannot undestand :


Operations on the Unicode byte arrays require that some parameters have even values


What would be the minimal steps to go from xmlserializer to OracleClob ?

Answer Source

Passing from 1000 to 100000 buffer size speed up the process a lot.

Each clob.write is a request to database, so by doing that it lowers number of request to database.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download