Transaction Problem


Author
Message
dgsoft
dgsoft
StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)
Group: StrataFrame Users
Posts: 93, Visits: 236
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
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
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")




Edhy Rijo
E
StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
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.




Edhy Rijo

dgsoft
dgsoft
StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)
Group: StrataFrame Users
Posts: 93, Visits: 236
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..
dgsoft
dgsoft
StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)
Group: StrataFrame Users
Posts: 93, Visits: 236
Hi, in my case its DataSourceKey.. I will try to check it with another constructur..
Edhy Rijo
E
StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
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")



Edhy Rijo

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Try Edhy's sample...that should work.
dgsoft
dgsoft
StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)
Group: StrataFrame Users
Posts: 93, Visits: 236
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
dgsoft
dgsoft
StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)
Group: StrataFrame Users
Posts: 93, Visits: 236
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!
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Great. Smile
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search