After lots of searching and working and trying, I have came up with the following solution:
You cannot use ExecuteStoreCommand() method in order to insert a string which is longer than 4K.
In order to add string more than 4K, you have to bind parameters.
In order to bind parameters in .net, we will utilize odp.net.
Step One
Add the reference to your project.
- Right click references on .net project explorer window and click add reference.
- On .net tab, find Oracle.DataAccess and add this to project.
Step Two
Add this to your top of your page:
using Oracle.DataAccess.Client;
Step Three
Now we code:
using (OracleConnection con = new OracleConnection("Here comes your oracle connection string."))
{
con.Open();
//prepare the command
OracleCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = @"INSERT INTO MyTable VALUES (:param0) ";
//define the parameter.
OracleParameter param0 = new OracleParameter();
param0.OracleDbType = OracleDbType.Clob;
param0.Value = "very long xml...";
param0.ParameterName = "param0";
cmd.Parameters.Add(param0);
try
{
AffectedRows = cmd.ExecuteNonQuery(); //execute the query
}
catch (Exception e)
{
return 0;
}
}
Now it should work like a charm :)
Notes
1- Do not use System.Data.OracleClient, it is deprecated.
2- If your table column data type is xmltype and still get an error, change your datatype to clob.
Hope this helps others...