Should saving 1 child object cause a MSDTC transaction?

Should saving 1 child object cause a MSDTC transaction?

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


cmay posted on Monday, May 11, 2009

I have collection of switchable objects.  This collection inherits from BusinessListBase.

I have this code for saving changes to the collection:

<Transactional(TransactionalTypes.TransactionScope)> _

Protected Overridable Overloads Sub DataPortal_Update()

Me.Child_Update(Me)

End Sub

Now, when I run this and make only 1 change to a single child object, an MSDTC transaction is created.  If I stop the MSDTC service on my laptop, this action will fail with the error:

DataPortal.Update failed (Csla.DataPortalException: ChildDataPortal.Update failed on the server ---> Csla.Reflection.CallMethodException: Child_Update method call failed ---> System.Data.SqlClient.SqlException: MSDTC on server 'mylaptop' is unavailable.

 

I had thought that CSLA would not involve the transaction unless it was needed (i.e. more than 1 BO was changed in the list).  Did I remember that wrong?

 

By using the Transactional attribute, am I forcing a transaction even though none is really required?  I tried running my code w/o that attribute and transactions are never invoked even if I have many changes that are being saved.

Any help would be appreciated.

 

 

Marjon1 replied on Tuesday, May 12, 2009

The reason you would be getting this message is because you are opening a second connection within your child_update methods, instead of using the connection manager to re-use the existing connection.

The transaction is created once you go into the method and if a second connection is opened anytime while the transaction is outstanding, you will get the MSDTC issue.

Hopefully this clears things up for you.

cmay replied on Tuesday, May 12, 2009

I'm afraid I still am not quite sure. 

From what I can tell, there is only 1 time when I open a connection.... when I save the 1 child object that has changes.  The first child object who's dataportal is called starts the transaction, so if that is the 2nd connection when is the first connection opened?

Marjon1 replied on Wednesday, May 13, 2009

Normally, for the child object to be saved it should be being called within the DataPortal_Insert/Update method of the root object that this child belongs to. That insert/update would normally have an open connection associated with it.

If you can past some code here it might make it a bit easier to explain.

Is this child object a single object or a child list?

cmay replied on Thursday, May 14, 2009

Thanks for sticking with me.  I'll post some code below.

Also, I should note, it's possible that I have been using the wrong terms when calling these objects Child objects.  Really, they are just switchable items that belong to a Collection/list.

So, lets say I have PlayersList, inherits BusinessListBase, containing a bunch of Player objects.

...............

I had put a bunch of code here, but I think in going over the code to copy, I found the issue.

Inside my function that does the "Save",  I am using the MS data access blocks. 

One of their lines is:

storedParams = SqlHelperParameterCache.GetSpParameterCollection(ConnectionString, "Players_Search")

I think that is hitting the database, thus, that is the first connection.

Later the actual save takes place... the 2nd connection.

I am going to test and report back.

 

 

 

 

 

Copyright (c) Marimer LLC