user1740075
user1740075

Reputation: 1

Kentico transactions and rollback of data

I am performing an import of data wrapped in a CMSTransactionScope.

What would be the most efficient and practical way to import data in parallel and rollback if any errors? The problem I see is that, with it being parallel, I don't know if I can have the inserted objects be part of the transaction if they are apart of a new thread.

Is there any way to do this or should it be handled differently?

Upvotes: 0

Views: 393

Answers (1)

rocky
rocky

Reputation: 7696

If you're running the code in parallel in order to achieve better performance and you are basically inserting rows one by one then it's unlikely that it'll perform any better than it would while running in a single thread. In this case I'd recommend using one thread in combination with CMSTransactionScope, and potentially ConnectionHelper.BulkInsert.

Anyway, if you still want to run your queries in parallel then you need to implement some kind of synchronization (locking, for instance) to ensure that all statements are executed before the code hits CMSTransactionScope.Commit() (this basically means a performance loss). Otherwise, queries would get executed in separate transactions. Moreover, you have to make sure that the CMSTransactionScope object always gets instantiated with the same IDataConnection (this should happen by default when you don't pass a connection to the constructor).

The second approach seems error prone to me and I'd rather take a look at different ways of optimizing the code (using async, etc.)

Upvotes: 1

Related Questions