Skip to content

[BUG] - Using latest Oracle.ManagedDataAccess.OracleBulkCopy corrupts any data inserted into CLOB columns. #371

@carmanj

Description

@carmanj

Hi there,

We recently switched from using the unmanaged Oracle.DataAccess driver to using the Oracle.ManagedDataAccess driver. It appears that data corruption is occurring when using ManagedDataAccess.OracleBulkCopy to load data into tables that have CLOB columns. See below for a code sample to demonstrate the issue.

using Oracle.ManagedDataAccess.Client;
using System.Collections.Generic;
using System.Configuration;
using System.Data;

namespace OracleBulkCopy_Demo
{
    internal class Program
    {
        static void Main(string[] args)
        {
            using (OracleConnection connection = new OracleConnection(ConfigurationManager.ConnectionStrings["alphaora15"].ConnectionString))
            {
                connection.Open();
                using (OracleBulkCopy bulkCopy = new OracleBulkCopy(ConfigurationManager.ConnectionStrings["alphaora15"].ConnectionString)
                { DestinationTableName = "EMAILS", BulkCopyTimeout = 600, BatchSize = 200000 })
                {
                    var emails = new List<EMAILS>
                    {
                        new EMAILS { EMAILID = 1, SUBJECT = "ABCD_TEST1", BODY = "First test body." },
                        new EMAILS { EMAILID = 2, SUBJECT = "ABCD_TEST2", BODY = "Second test body." }
                    };

                    // Convert list of emails to DataTable
                    DataTable dataTable = new DataTable();
                    dataTable.Columns.Add("EMAILID", typeof(string));
                    dataTable.Columns.Add("SUBJECT", typeof(string));
                    dataTable.Columns.Add("BODY", typeof(string));

                    foreach (var email in emails)
                    {
                        dataTable.Rows.Add(email.EMAILID, email.SUBJECT, email.BODY);
                    }
                    bulkCopy.WriteToServer(dataTable);
                }
                connection.Close();

                /*
                 * Result:
                 *  EmailID: 1, Subject: 䅂䍄彔䕓吱 (hex: BADCT), Body: 䙩牳琠瑥獴⁢潤礮 (hex: iFsr tett)
                 *  EmailID: 2, Subject: 䅂䍄彔䕓吲 (hex: BADCT), Body: 卥捯湤⁴敳琠扯摹 (hex: eSocdnt s)
                 */
            }
        }

        public struct EMAILS
        {
            public int EMAILID;
            public string SUBJECT;
            public string BODY;
        }
        /*
         * SCHEMA:
            CREATE TABLE Emails (
              EmailID INTEGER,
              Subject CLOB NULL,
              Body CLOB NULL
            );
        */
    }
}

It seems apparent that there is a very particular character encoding problem happening when using OracleBulkCopy on CLOB columns when examining the hex values and comparing them to the expected result.

image
image

Driver versions: 21.11.0 -21.13.0, 23.3.2-dev
Oracle Version: 19.3.0.0
.NET Version: 4.8

Can a bug be submitted/tracked to resolve this issue? Let me know if anything else is needed.

Thanks,
Justin Carman

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions