Truncating size of byte[] data to 2000 when insert data into Oracle DB

Jun 15 2007 10:37 AM

Inserting byte[] data into Oracle DB works fine until I insert it within a Transaction. If done within transaction then it will always truncate the byte array to 2000 bytes. Here is the sample code:

// These are the 2 values (string and byte array of 3456 bytes) that will insert.
byte[] theBytes = File.ReadAllBytes("C:\\Test.jpg");
OracleParameter strParam = new OracleParameter();
strParam.OracleType = OracleType.VarChar;
strParam.Value = "The string value";
strParam.ParameterName = "STRPARAM";
OracleParameter blobParam = new OracleParameter();
blobParam.OracleType = OracleType.Blob;
blobParam.Value = theBytes;
blobParam.ParameterName = "BLOBPARAM";

// Setup insert statement.
OracleConnection connection = new OracleConnection(connectionString);
OracleCommand command = new OracleCommand(
"Insert into MYTABLE(STRFLD, BLOBFLD) 
                                                                    values (:STRPARAM, :BLOBPARAM)"
, connection);
command.Parameters.Add(strParam);
command.Parameters.Add(blobParam);
connection.Open();

// If comment out the transaction part then insert works.
// If leave like it is then truncates byte[] data to 2000 bytes.
command.Transaction = connection.BeginTransaction();
command.ExecuteNonQuery();
command.Transaction.Commit();

Does anyone know why this happens? Any help would be much appreciated.

Thanks,
Keith


Answers (1)