views:

354

answers:

2

Hello,

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

A: 

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

FerranB
This has nothing to do with my questions. Using internal transaction per batch will not help me to rollback the bulk of rows inserted. Basically I want to rollback everything. Let say you have to insert 100K rows and somewhere in the middle you want to rollback everything not the last 50K while the first 50K is already committed.
I know. I said about a test to see if all is working fine. as the documentation says, if you have UseInternalTransaction and use BeginTransaction an exception is raised. If the exception is not raised may be the trouble is that the transaction is not started.
FerranB
Yes, it does raise the exception if you use the UserInternalTransaction. I have had tried that. Also I have tried using CommittableTransaction as explicit distributed transaction. This didn't help either.
I have tried TransactionScope as well. That didn't work too.
A: 

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