Reputation: 13
I'm new here. I have a problem. I want to execute this code in C#:
string XMLData = File.ReadAllText(App.FolderImport + "\\" + FileName);
Command.CommandType = CommandType.StoredProcedure;
Command.CommandText = "PKG_DATA_EXCHANGE.IMPORT_DATA";
Command.Parameters.Add("pID_USER_M", OracleType.Number).Value = App.User.IdUser;
Command.Parameters.Add("pFILE_NAME", OracleType.VarChar).Value = FileName;
Command.Parameters.Add("pXMLDATA", OracleType.Clob).Value = XMLDataString;
Command.ExecuteNonQuery();
It works fine for small XMLDataString, but if it is bigger then I get exception
ORA-01460
.
I understand that it is linked somehow to CLOB problem, but I don't know how to solve it.
I was searching for such problem here, but I had no luck.
Please any help, links or code will be very appreciated!
Upvotes: 1
Views: 4254
Reputation: 173
A solution is to create an OracleClob object that receives an Open() connection and then we write the value as an Array of Bytes to it.
If you are using EF and Context you can access the conectionString as follows:
string connectionString = _context.Database.GetDbConnection().ConnectionString;
The code would look like this:
using OracleConnection connection = new(connectionString);
try
{
connection.Open(); //required
byte[] arrayByte = System.Text.Encoding.Unicode.GetBytes(audit.AuditRecord);
OracleClob oracleClob = new (connection);
oracleClob.Write(arrayByte, 0, arrayByte.Length);
var parameters = new OracleParameter[]
{
new OracleParameter("param1", OracleDbType.Varchar2, valueParam1, ParameterDirection.Input),
new OracleParameter("param_clob", OracleDbType.Clob, oracleClob, ParameterDirection.Input),
new OracleParameter("p_refcursor", OracleDbType.RefCursor, ParameterDirection.Output)
};
OracleCommand cmd= new("SCHEMA.STORED_PROCEDURE_NAME", connection)
{
CommandType = CommandType.StoredProcedure,
};
cmd.Parameters.AddRange(parameters);
cmd.ExecuteNonQuery();
//getting the returned values
var result = (OracleRefCursor)cmd.Parameters["p_refcursor"].Value;
var reader = result.GetDataReader();
reader.Read();
// To access the returned values
//reader.GetOracleValue(0)
//reader.GetOracleValue(1)
//reader.GetOracleValue(2)
}
finally
{
connection.Close();
}
Upvotes: 0
Reputation: 26
There are other reported causes of the ORA-01460 as well:
It appears, according to information on bug 5872943, that the ORA-01460 associated with ODP.NET, while not an ODP error, persisted through database version 11.2 where it has been reported as fixed.
Upvotes: 1