tags:

views:

475

answers:

2

Hey everyone,

So this is what I have so far. Am I doing something wrong or is there a bug in 3.0.0.3?

    var Repository = new SimpleRepository("DBConnectionName");

    using (TransactionScope ts = new TransactionScope())
    {
        using (SharedDbConnectionScope scs = new SharedDbConnectionScope("connstring", "providerName"))
        {
            try
            {
                for (int i = 0; i < 5; i++)
                {
                    Supplier s = new Supplier();
                    s.SupplierCode = i.ToString();
                    s.SupplierName = i.ToString();

                    Repository.Add<Supplier>(s);
                }

                ts.Complete();
            }
            catch
            {
            }
        }
    }

I'm getting an error in SubSonic DbDataProvider public DbConnection CurrentSharedConnection { get { return __sharedConnection; }

        protected set
        {
            if(value == null)
            {
                __sharedConnection.Dispose();

etc.. __sharedConnection == null :( Object Null Reference Exception :(

A: 

Perhaps switching the SharedDbConnectionScope and TransactionScope around may help.

using (SharedDbConnectionScope scs = new SharedDbConnectionScope("connstring", "providerName"))
{
    using (TransactionScope ts = new TransactionScope())
    {
    }
}
BlackMael
A: 

This will happen when Migration is set - On tablemigration the dbconnection will be closed.

Try the SimpleRepository with SimpleRepositoryOptions.None.

Don't know if this is a bug. I think the transactions don't work with SimpleRepository, I've always half of the data saved when throwing an exception in the transaction... perhaps it's only for ActiveRecord? Anybody knows?

Rumpel