I am trying to insert an Xml fragment with a size of more than 4000 characters in an XmlType field in an Oracle table.
My code initially worked as follows:
DbParameter parameter = new DbParameter;
parameter = clientFactory.CreateParameter(":p_xml_data", DbType.AnsiString, messageToLog.Length, ParameterDirection.Input, messageToLog);
However, as soon as I started trying to insert Xml blocks larger than 4000 bytes, I got:
ORA-01461: can bind a LONG value only for insert into a LONG column
This is the same problem as this question 2508987 / insert-xml-with-more-than-4000-characters-into-a-oracle-xmltype-column , however I don't have DbType.Clob as an option (it doesn't exist).
Next I tried to change the type to DbType.Object, hoping that it just converts it to what it needs, but I get this message:
Cannot bind type System.String as Blob
Then I tried using DbType.XML, I changed my code to move messageToLog to a SqlXml object:
SqlXml sx;
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(messageToLog);
using (XmlNodeReader xnr = new XmlNodeReader(xmlDoc))
{
sx = new SqlXml(xnr);
}
And changed the parameter accordingly:
parameter = providerFactory.CreateParameter(":p_xml_data", DbType.Xml, messageToLog.Length, ParameterDirection.Input, sx);
Now I get:
Value is not valid for DbType: Xml
XML .