WonderTiger WonderTiger - 28 days ago 8
C# Question

SqlBulkCopy.WriteToServer abort, OperationAbortedException?

I'm currently running two tasks which are copying data to my SQL Server. The data copying is done by the method

SqlBulkCopy.WriteToServer
. I'm using the
SqlRowsCopiedEvent
to show the user the amount of rows that are successfully copied. Every time this event is called I'm checking if the cancellation token is requested. If the token is requested (button click) I'm setting
SqlRowsCopiedEventArgs.Abort
to
true
. This aborts the
SqlBulkCopy.WriteToServer
method.

Now I'm getting an
OperationAbortedException
. I looked at the documentation and it says that this exception is thrown whenever the user is cancelling an operation. However I'm not 100% sure if it's right that this indeed throws when I abort the write to server method?

usr usr
Answer

The documentation states that this exception is thrown in this case. This is normal behavior.

Comments