StrataFrame Forum

Transaction Problem

http://forum.strataframe.net/Topic23269.aspx

By dgsoft - 6/1/2009

Hi,

I have a problem with transaction. I want to save data in 4 diffrent BO as "All or Nothing"

My code is







Try

BusinessLayer.TransactionBegin("PENSOLUTIONOFFICE", Data.IsolationLevel.ReadCommitted)

mmks_UpdateSFSUsers(loSFSUserBO)



lSaveResult = loSFSUserBO.Save()

If lSaveResult = MicroFour.StrataFrame.Data.SaveUndoResult.Success Then

pmks_SFSUserId = loSFSUserBO.us_pk

Dim loPSOClients As PSOClientsBO = New PSOClientsBO()

Dim lcKey As String = loSFSUserBO.DataSourceKey

loPSOClients.mmks_FillDataTableBySFSUserId(pmks_SFSUserId)

mmks_UpdatePSOClients(loPSOClients, pmks_SFSUserId)

Dim loSFSUsersXRoles As MicroFour.StrataFrame.Security.BusinessObjects.SFSUsersXRolesBO = New MicroFour.StrataFrame.Security.BusinessObjects.SFSUsersXRolesBO()

loSFSUsersXRoles.FillAllByUser(pmks_SFSUserId)

mmks_UpdateSFSUsersXRoles(loSFSUsersXRoles, pmks_SFSUserId)

Dim loSFSUsersXPermissions As MicroFour.StrataFrame.Security.BusinessObjects.SFSUsersXPermissionsBO = New MicroFour.StrataFrame.Security.BusinessObjects.SFSUsersXPermissionsBO()

loSFSUsersXPermissions.FillAllByUser(pmks_SFSUserId)

mmks_UpdateSFSUsersXPermissions(loSFSUsersXPermissions, pmks_SFSUserId)

Throw New Exception("Custom Error")

If loPSOClients.Save(True) = MicroFour.StrataFrame.Data.SaveUndoResult.Success Then

If loSFSUsersXRoles.Save(True) = MicroFour.StrataFrame.Data.SaveUndoResult.Success Then

If loSFSUsersXPermissions.Count > 0 Then

If Not loSFSUsersXPermissions.Save(True) = MicroFour.StrataFrame.Data.SaveUndoResult.Success Then

Throw New Exception("An error happen during save SFSUsersXPermissions")

End If

End If

Else

Throw New Exception("An error happen during save SFSUsersXRoles")

End If

Else

Throw New Exception("An error happen during save PSOClients")

End If

Else

Throw New Exception("An error happen during save SFSUsers")

End If



BusinessLayer.TransactionCommit("PENSOLUTIONOFFICE")



Catch ex As Exception

lcErrorMessage = ex.Message

BusinessLayer.TransactionRollback("PENSOLUTIONOFFICE")

End Try









At the middle of code I made Throw New Exception("Custom Error") - so code goes to Catch block and must Rollback transaction.

but - in my data table I can see written new values!

Why data changes was not revert?



Thanks

Denis
By Trent L. Taylor - 6/1/2009

You did not tell the BO to save on the transaction that you created. You can start more than one transaction session and save each BO in a different transaction if you had that need. But in your case, you created the transaction then did not tell the BO to save on that transaction.



loPSOClients.Save(True, "PENSOLUTIONOFFICE")



By Edhy Rijo - 6/1/2009

Hi Denis,



The BO.TransactionBegin() has 2 constructors, I use the 2nd one with 3 parameters, DataSourKey, TransactionKey and IsoLevel, the main one for me is the TransactionKey which I also used as the 2nd parameter of my Save(True, TransactionKey). In your case I don't know if "PENSOLUTIONOFFICE" is the DataSourceKey or the TransactionKey, so pass the TransactionKey to the Save() and you should be fine.


By dgsoft - 6/1/2009

Hmm. but when I add second parameter.. I not able to save the data because an error happen



"An error occurred while saving the data to the server."



[code]



Dim loSFSUserBO As MicroFour.StrataFrame.Security.BusinessObjects.SFSUsersBO = New MicroFour.StrataFrame.Security.BusinessObjects.SFSUsersBO()

If llNewUser Then

loSFSUserBO.Add()

Else

loSFSUserBO.FillByPrimaryKey(pmks_SFSUserId)

End If





Try

BusinessLayer.TransactionBegin("PENSOLUTIONOFFICE", Data.IsolationLevel.ReadCommitted)

mmks_UpdateSFSUsers(loSFSUserBO)



lSaveResult = loSFSUserBO.Save(True, "PENSOLUTIONOFFICE")



[code]



IsDirty = true here.. and on Save line I have an exception..
By dgsoft - 6/1/2009

Hi, in my case its DataSourceKey.. I will try to check it with another constructur..
By Edhy Rijo - 6/1/2009

dgsoft (06/01/2009)
Hi, in my case its DataSourceKey.. I will try to check it with another constructur..




Try this:



Try

BusinessLayer.TransactionBegin("PENSOLUTIONOFFICE","MyTransationKey", Data.IsolationLevel.ReadCommitted)

mmks_UpdateSFSUsers(loSFSUserBO)



lSaveResult = loSFSUserBO.Save(True, MyTransationKey")

By Trent L. Taylor - 6/1/2009

Try Edhy's sample...that should work.
By dgsoft - 6/1/2009

You are right!

The problem was in TransactionBegin() method. When I send 3 parameters DataSourceKey, TransactionKey and IsolationLevel - now all works perfect!

Thank you for Help!



Denis
By dgsoft - 6/1/2009

Yes.. the problem was - I use only 2 parameters in the TransactionBegin DataSourceKey and IsolationLevel.. now when I use another method overload - it works perfect!

Problem is solved!

Thank you!
By Trent L. Taylor - 6/1/2009

Great. Smile
By Edhy Rijo - 6/1/2009

Glad to heard that. Good luck!