Hoang
Hoang

Reputation:

How to rollback OracleBulkCopy() inserted rows?

I have tried to roll back external transaction and also tried to abort OracleBulkCopy() but it still inserted all rows. Anyone knows how to do this?

Case 1: Didn't work. All row inserted anyway.

OracleConnection connection = new OracleConnection(ConnectionString);
connection.Open();
OracleTransaction trans = connection.BeginTransaction();
OracleBulkCopy bulkCopy = new OracleBulkCoopy(connection,OracleBulkCopyOptions.Default);
bulkCopy.DestinationTableName = "SomeTable";    
bulkCopy.WriteToServer(SomeDataTable);
trans.Rollback();

Case 2: Use OracleRowsCopiedEventHandler delegate and in this callback set Oracle.RowsCopiedEventsArgs.Abort to true and then rollback on the transaction in catch block. Didn't work either. It seems that whatever insertion before the Abort call is already in the database. OracleBulkCopy() is inferior to SqlBulkCopy() the way I see it.

Thanks. Hoang

Upvotes: 1

Views: 4021

Answers (2)

Hoang
Hoang

Reputation:

OK, I have gotten the answer from Oracle. Transaction is not supported with OracleBulkCopy currently.

Upvotes: 1

FerranB
FerranB

Reputation: 36827

Have you tried to set OracleBulkCopyOptions.UseInternalTransaction instead of OracleBulkCopyOptions.Default to see if the exception InvalidOperationException is raised as the documentation claims?

Upvotes: 0

Related Questions