Question

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)

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top