Transaction not working as expected.

Transaction not working as expected.

Old forum URL: forums.lhotka.net/forums/t/8228.aspx


MadGerbil posted on Tuesday, December 29, 2009

In a root business object I have the following code:

ROOT OBJECT
[Transactional(TransactionalTypes.TransactionScope)]
private void Child_Update()
{
using (var ctx = ConnectionManager.GetManager("eGA"))
{
using (SqlCommand cm = ctx.Connection.CreateCommand())
{
//Update the root object

FieldManager.UpdateChildren(this);
}
}
}

CHILD COLLECTION
protected override void Child_Update(params object[] parameters)
{
base.Child_Update(parameters);
}

CHILD OBJECT (Contained in the collection)
private void Child_Insert()
{
using (var ctx = ConnectionManager.GetManager("eGA"))
{
using (SqlCommand cm = ctx.Connection.CreateCommand())
{
//test error
throw new Exception("Oopsie Doodle");

//Update child object
}
}
}

When I throw the exception (for test purposes) in the child object the changes which were made to the root object are still in the database when I would have expected them to be rolled back. Obviously, this isn't working as a transaction. What have I missed?

lukky replied on Tuesday, December 29, 2009

Hi,

Maybe it's a typo, but shouldn't your root object implement dataportal_Update() instead of Child_Update() ? Not sure what side effects that might have.

rxelizondo replied on Tuesday, December 29, 2009

I think “lukky” made a good observation.

Do you have a DataPortal_Update method included in your class and if so, is that method decorated with the [Transactional(TransactionalTypes.TransactionScope)] attribute also?

But the again, it must be a typo since you also have the child object code calling Child_Insert() instead of Child_Update()

ajj3085 replied on Tuesday, December 29, 2009

Also, the Child_Update and Child_Insert on the actualy child BB subclass should take a ROOT parameter, since you call FieldManager.UpdateChildren( this ).

MadGerbil replied on Tuesday, December 29, 2009

Thank you for the input.
Typos aside, the saving of the object works but when I put the TransactionScope on the root object I get the following error:

The partner transaction manager has disabled its support for remote/network transactions.

Evidently I need to crack the books and get my head around what CSLA is doing. I've worked with it for years but my understanding of it is pretty shallow.

ajj3085 replied on Tuesday, December 29, 2009

I don't think this has anything to do with Csla.  It sounds more like the database end of things.  What version of Sql Server are you using? 

MadGerbil replied on Tuesday, December 29, 2009

I'm using SQL Server 2005.

I'm going to put together a test project and put a really, really simple object structure in there and see if I can get it to work. I'll report back here with the results.

bmmathe replied on Monday, January 25, 2010

What did you find?
I'm having the same issue but not consistently. With a simple parent > child update this code works with no problems but with a more complex situation the transaction does get promoted to the DTC.
The issue was resolved when we upgraded to SQL Server 2008.

lukky replied on Tuesday, December 29, 2009

Well, it seems to me from the error message that you're trying (for some reason) to initiate a distributed transaction, which would require MSDTC to be enabled.

The question is, do you really want to use a distributed transaction ? This would be the case if you were to use two different connections within the same transactionscope. Is it what you're trying to do ?

if not, then I think you need to review the way your parent/child Dataportal methods interact so that you won't create 2 connections.

If yes, then you need to enable MSDTC in order to allow more than one connection within the transaction.

BTW, I'm no expert on DTC. Anyone feel free to correct me.

Regards

Copyright (c) Marimer LLC