views:

137

answers:

1

I'm developing a module in DNN 4.9 to import users.

My problem is that I need transaction support but have to use DNN classes to import/create users. Out of the box the classes don't seem to support transactions.

Anybody got experience with this or knows how to do that?

I'm using the following object to create users:

UserController.CreateUser(ref UserInfo) ...

As I'm improving an existing module and a complete rewrite/change of the way how to import is not an option. (like using SQL statements directly to create users)

Thanks a mil!

A: 

I'm not a DNN user, but whithin the context of a CLR transaction any ADO.Net operation will automatically enroll into the transaction:

 using(TransactionScope scope = new TransactionScope(
     TransactionScopeOption.Required))
 {
      UserController.CreateUser(ref UserInfo) 
      ...
      scope.Complete();
 }

Unless some DNN code explicitly disables the transaction scope (by creating a new scope with the option Supress) then the actual database work will be enrolled in the appropiate transaction (eg. any SqlClient operation will be enrolled into a SqlTransaction).

Update

Transaction scope is a context object that is associated with the current thread. Once created, .Net components that check for its existence will find it and know that they have to participate in the transaction.

File operation cannot enroll into a transaction scope because the underlying file system does not support transactions (at least not until Win7). Components like SQL Server provider, Oracle Provider, MSMQ accessor and other .Net components that support transactions will start a transaction and add it to the current scope. When the scope is 'complete', the equivalent SqlTransaction is committed. If the scope 'ends' (ie. its Dispose method is called because it reaches the end of the using block) but does not 'complete', the SqlTransaction is rolled back.

If multiple components enroll in a single transaction scope then they will become part of a distributed transaction. This can happen with something as simple as using two separate connections while under a transaction scope. The ADO.Net will automatically enroll them in a true distributed transaction.

Remus Rusanu
thanks! I know somewhere in the back of my head that this exists. Can you explain a bit more detail what the scope is?, does this include actions like file operations ? How do I give you the bounty now?
Johannes
See my updates. The bounty is rewarded to the answer you select as 'accepted'.
Remus Rusanu