dotnet-db-samples: [BUG] - Using latest Oracle.ManagedDataAccess.OracleBulkCopy corrupts any data inserted into CLOB columns.
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.
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
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 17 (8 by maintainers)
ODP.NET 21.15 now available.
Hi Alex,
Sorry for the delay. We sorted things out internally and renewed support. I should be able to submit that SR against this bug within the next day or so. I appreciate your effort and all the background information on this.
Thanks! Justin Carman
We’ll fix the bug as typical. We just won’t have a way to validate it in your environment. We’ll validate it in our own. Then, we ship the bug fix as part of our next ODP.NET quarterly patch release on NuGet Gallery.
Hi Justin, It most likely looks is a conversion issue for ODP.NET bulk copy with UFTF8 CLOB/NCLOB, not a DB issue.
Hi Justin, We were able to reproduce the bug now. Your team can still file an SR. When we have a verification patch ready, you can try it out via the SR.
Hi Justin, I filed bug 36442140 to track this issue.
After discussing this issue with the ODP.NET dev team, there may be an issue with your CLOB and NCLOB binding when using UTF8. Can your team open an Oracle Support service request (SR) and reference this bug? My team can then provide you with a diagnostic drop to verify the root cause, or at least narrow it down significantly.
Usually, your Oracle DBA will be able to open up the SR for you.