Yitzchok / subsonicproject

Automatically exported from code.google.com/p/subsonicproject
0 stars 0 forks source link

DbDataProvider does not take SharedConnection into account on ExecuteXXX methods in version 3.0 #95

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I'm using the System.Transactions namespace to enforce a transaction on 
multiple actions.

To ensure that the same DbConnection is used, I am creating an 
SharedDbConnectionScope instance "around" the statements, much like the 
following code (that I took from yours SqlQuery class):

public static void ExecuteTransaction(List<SqlQuery> queries)
{
    using (new SharedDbConnectionScope())
    {
        using (new TransactionScope())
        {
            foreach (SqlQuery query in queries)
            {
                query.Execute();
            }
        }
    }
}

The problem is that MSDTC "fires" anyway... 

SqlQuery objects "dispatch" their execute methods to their associated data 
provider's corresponding Execute method.

I saw the code of the DBDataProvider and, for example, ExecuteQuery and 
ExecuteScalar, both create new connections, ignoring the 
CurrentSharedConnection in effect on that same data provider.

This is a shame for me and the project I am working on cause we have no 
other way to change this behaviour. Do You know Of Any? If we had the 
source code we could recompile it with the fix.

Original issue reported on code.google.com by duarte.leao on 2 Jun 2009 at 12:12

GoogleCodeExporter commented 9 years ago
I'm sure you wanted to posth this issue to
http://code.google.com/p/subsonicthree/issues/list ;-)

Anyway, I think you have to wrap the TransactionScope around the 
SharedDbConnectionScope.

To explicitly force a new Transaction you can add the RequireNew option:

            using (TransactionScope ts = new
TransactionScope(TransactionScopeOption.RequiresNew))
            {

            }

Original comment by j.steinblock@gmail.com on 4 Jun 2009 at 6:10