views:

355

answers:

1

I see there are two main options for managing transactions with llblgen.

Method 1:

using(DataAccessAdapter adapter = new DataAccessAdapter())
{
    adapter.StartTransaction(IsolationLevel.ReadCommitted, "TR");
    try
    {
        // ...
        adapter.Commit();
    }
    catch
    {
        adapter.Rollback();
        throw;
    }
}

Method 2:

using(TransactionScope scope = new TransactionScope())
{
    // ...
    scope.Complete();
}

What is your prefered method and why? (I'm using adapapter/2.6 .net/3.5)

+1  A: 

I would lean towards using TransactionScope for managing transactions as this is what it was designed for whereas the DataAccessAdapter, while it has the ability to create transactions is designed primarily for DataAccess.

To try and be a little clearer, you could use TransactionScope to manage multiple transactions across multiple DataAccessAdapters whilst a single DataAccessAdapter appears to have a specific scope.

For example:

using(TransactionScope ts = new TransactionScope())
{
    using(DataAccessAdapter d1 = new DataAccessAdapter())
    {
        //do some data access stuff
    }
    using(DataAccessAdapter d2 = new DataAccessAdapter())
    {
        //do some other data access stuff  
    }
    ts.complete();
}

Another side note is that TransactionScope is thread safe, where as DataAdapters are not.

lomaxx
In your experience, has TransactionScope always worked like you'd expect? There is very little to it, but I'm still wondering if there are any gotchas.
jayrdub
it has always worked like i expect, however i would encourage you to read the doco and understand why it's doing what it does, particularly in regards to nested transactionscope objects and multiple transactions.
lomaxx