From C#, How to pass a clob value to oracle stored procedure

11,053

I got it working yesterday , Hope it will help some one.

Clob data we need to pass to stored procedure by creating an OracleClob object

OracleClob clob = new OracleClob(connection);
clob.Write(xmlContent.ToArray(), 0, xmlContent.Length);
clob_Param.Value = clob;

where clob_Param is of type OracleParameter.
After creating the OracleClob object, write xml content to it !!!

Share:
11,053
subi_speedrunner
Author by

subi_speedrunner

Curious, day- dreamer, explorer

Updated on June 07, 2022

Comments

  • subi_speedrunner
    subi_speedrunner almost 2 years

    My Oracle stored procedure is accepting a clob type parameter.

    procedure  p_insert_data(xml_string in clob)
    

    From C#, I am trying to call the procedure by passing clob data, which is an XML file.

    Following is the way which I tried:

    Converting XML to string

     XmlDocument xmlDoc = new XmlDocument();
     xmlDoc.Load(@"D:\Response_min.xml");
    
     string xml = xmlDoc.OuterXml;
    

    Passing clob data to stored procedure from C#

    OracleParameter p_data = new OracleParameter("p_xml_string", OracleDbType.Clob);
    p_data.Direction = ParameterDirection.Input;
    p_data.Value = xml; //xml is of string type 
    dbCommand.Parameters.Add(p_data);
    dbCommand.ExecuteNonQuery();
    

    I am getting exception

    operation not valid due to current state of object

    Instead of xml string, I tried passing bytes[] to clob parameter but still no luck.

    I also tried to use XML which has less content.
    Anyone has any clue about how I should pass clob value ?