views:

54

answers:

1

I have a WinForm application which uses SqlServer CE 3.5 as database. I use typed dataset queries for db operations. I need to use transactions for this operations. The problem is, they're scattered across different assemblies. My question is, what should I use to run all of them in a single transaction? Here's an example operation:

//transaction should start here
this.QueryDb();
MyOtherAssembly.myClass.QueryDbForSomethingElse();
System.IO.File.Delete(fileName);
//end transaction

I'm thinking of using TransactionScope but would it work in this situation? I mean would QueryDbForSomethingElse() rollback if File.Delete() fails? Should I pass Transaction.Current or Transaction.Current.DependentClone(DependentCloneOption.BlockCommitUntilComplete) as a parameter to it and create a new transaction there using passed parameter?

I'd appreciate any ideas on this.

A: 

TransactionScope works across assemblies - it really doesn't care where the code is implemented. Rather, it's tied to the current execution context (the current thread, if I'm not mistaken).

However, the Windows file system is not transactional, so no matter how you attempt to enroll your code in a transaction, file operations are not going to take any part in that. Until we get a transactional file system, you can't write an application that guarantees ACID transactions if file operations are involved.

Instead, you will explicitly have to implement compensating actions.

FWIW, however, you may want to take a look at Juval Lowy's MSDN Magazine article Can't Commit? Volatile Resource Managers in .NET Bring Transactions to the Common Type.

Mark Seemann
Thanks.I should have been more clear and add that I don't need transactional file deleting and my operations are not multi-threaded..
Armagan