StrataFrame Forum

Transaction Commit problem

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

By dgsoft - 7/22/2009

Hi,

I deploy to customer my application. On my developer machine all works fine.. and as always on customer side all goes wrong Smile

The code is simple as on example



Try

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

mmks_updatePSOForm(loPSOFormStoreBO)



lSaveResult = loPSOFormStoreBO.Save(True, lcTransactionKey)

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

BusinessLayer.TransactionCommit("PENSOLUTIONOFFICE", lcTransactionKey)

lcErrorMessage = "SUCCESS"

Else

Throw New Exception("An error happen during save data!")

End If

Catch ex As Exception

lcErrorMessage = ex.Message

BusinessLayer.TransactionRollback("PENSOLUTIONOFFICE", lcTransactionKey)

End Try





On customer machine BusinessLayer.TransactionCommit call an exception (free translation from german) Transaction is finised and can't be used anymore.. something like that...

The question is WHEN transaction is finished? Smile and why on my developer machine all works fine and there an exception happens.

Everywhere installed SQL Server 2008.

Any ideas

Thanks

Denis
By Edhy Rijo - 7/22/2009

Hi Denis,



I don't see anything wrong with your code. Tongue



Make sure the customer have the correct SF assemblies you have in your developer computer. w00t
By dgsoft - 7/22/2009

Hi,

I have on developer machine in GAC a little bit more registered dlls but I thinking its not a problem

On my developer machine I have

MicroFour StrataFrame AddIns

MicroFour StrataFrame Base

MicroFour StrataFrame Business

MicroFour StrataFrame DBEngine

MicroFour StrataFrame Enterprise

MicroFour StrataFrame Enterprise Client

MicroFour StrataFrame Extensibility

MicroFour StrataFrame Infragistics Wrapper

MicroFour StrataFrame Inherited UI

MicroFour StrataFrame Security

MicroFour StrataFrame UI

All assemblies version 1.6.0.0 and all dlls version 1.6.6.9



On customer machine in GAC

MicroFour StrataFrame Base

MicroFour StrataFrame Business

MicroFour StrataFrame DBEngine

MicroFour StrataFrame Enterprise

MicroFour StrataFrame Enterprise Client

MicroFour StrataFrame Security

MicroFour StrataFrame UI

All assemblies version 1.6.0.0 and all Dlls version 1.6.6.9



Seems a same ...
By dgsoft - 7/22/2009

Is it possible to have something diffrent in SQL Server environment for transaction support.. I am not a big expert in SQL Server.. so.. as idea...
By Edhy Rijo - 7/22/2009

Are the tables structure at the customer site, the same as yours?
By Edhy Rijo - 7/22/2009

Also before the save, use code like this one to debug the data that is being send to the server:



MicroFour.StrataFrame.Data.DataBasics.DataSources("").SetDebugOn("c:\DebugFile.html", True)

By dgsoft - 7/22/2009

Thanks for response

yes.. database is a same.. I copy MDF file and attach it on customer side

Save is not a problem.. it works..



the debug file:

Command #:    1

Timestamp:    2009-07-22 21:37:35.93

General Command Settings

Command Type:    Text

Object Type:    System.Data.SqlClient.SqlCommand

Connection String:    Data Source=DIGIPENDEV2;Initial Catalog=AnotoOffice;User ID=anoto;

Transaction:    True

Command Settings

CommandText:    UPDATE [dbo].[PSOFormstore] SET [mandator_id] = @mandator_id, [filename] = @filename, [formsetid] = @formsetid, [active] = @active, [validForm] = @validForm, [validto] = @validto, [offsetx] = @offsetx, [offsety] = @offsety, [patternscalex] = @patternscalex, [patternscaley] = @patternscaley, [mergeOpenValue] = @mergeOpenValue, [mergeOpenUnit] = @mergeOpenUnit, [comment] = @comment, [pivotx] = @pivotx, [pivoty] = @pivoty, [rotate] = @rotate, [fs_us_pk] = @fs_us_pk, [xformxml] = @xformxml, [papersize] = @papersize, [frompage] = @frompage, [topage] = @topage WHERE [id] = @id AND (([timestamp] = @timestamp) OR (@timestamp IS NULL)); SELECT [timestamp] FROM [dbo].[PSOFormstore] WHERE [id] = @id;

Command Parameters

@mandator_id:    '0' [DbType: Int32 | Size: 0 | Direction: Input | SourceColumn: mandator_id | SourceVersion: Current]

@filename:    'Hartl_Besprechungsformular_Seite1.xform' [DbType: AnsiString | Size: 66 | Direction: Input | SourceColumn: filename | SourceVersion: Current]

@formsetid:    'Hartl_Besprechungsformular' [DbType: AnsiString | Size: 66 | Direction: Input | SourceColumn: formsetid | SourceVersion: Current]

@active:    '255' [DbType: Byte | Size: 1 | Direction: Input | SourceColumn: active | SourceVersion: Current]

@validForm:    '01.06.2009 00:00:00' [DbType: DateTime | Size: 0 | Direction: Input | SourceColumn: validForm | SourceVersion: Current]

@validto:    '11.06.2009 00:00:00' [DbType: DateTime | Size: 0 | Direction: Input | SourceColumn: validto | SourceVersion: Current]

@offsetx:    '0' [DbType: Int32 | Size: 0 | Direction: Input | SourceColumn: offsetx | SourceVersion: Current]

@offsety:    '0' [DbType: Int32 | Size: 0 | Direction: Input | SourceColumn: offsety | SourceVersion: Current]

@patternscalex:    '1' [DbType: Double | Size: 0 | Direction: Input | SourceColumn: patternscalex | SourceVersion: Current]

@patternscaley:    '1' [DbType: Double | Size: 0 | Direction: Input | SourceColumn: patternscaley | SourceVersion: Current]

@mergeOpenValue:    '0' [DbType: Int16 | Size: 0 | Direction: Input | SourceColumn: mergeOpenValue | SourceVersion: Current]

@mergeOpenUnit:    '' [DbType: AnsiString | Size: 11 | Direction: Input | SourceColumn: mergeOpenUnit | SourceVersion: Current]

@comment:    '' [DbType: AnsiString | Size: 257 | Direction: Input | SourceColumn: comment | SourceVersion: Current]

@pivotx:    '0' [DbType: Double | Size: 0 | Direction: Input | SourceColumn: pivotx | SourceVersion: Current]

@pivoty:    '0' [DbType: Double | Size: 0 | Direction: Input | SourceColumn: pivoty | SourceVersion: Current]

@rotate:    '0' [DbType: Int32 | Size: 0 | Direction: Input | SourceColumn: rotate | SourceVersion: Current]

@fs_us_pk:    '11' [DbType: Int32 | Size: 0 | Direction: Input | SourceColumn: fs_us_pk | SourceVersion: Current]

@xformxml:    '' [DbType: AnsiString | Size: -1 | Direction: Input | SourceColumn: xformxml | SourceVersion: Current]

@papersize:    'A5' [DbType: AnsiString | Size: 13 | Direction: Input | SourceColumn: papersize | SourceVersion: Current]

@frompage:    '1' [DbType: Byte | Size: 1 | Direction: Input | SourceColumn: frompage | SourceVersion: Current]

@topage:    '1' [DbType: Byte | Size: 1 | Direction: Input | SourceColumn: topage | SourceVersion: Current]

@id:    '2' [DbType: Int32 | Size: 0 | Direction: Input | SourceColumn: id | SourceVersion: Original]

@timestamp:    'System.Byte[]' [DbType: Binary | Size: 8 | Direction: Input | SourceColumn: timestamp | SourceVersion: Current]
By Edhy Rijo - 7/22/2009

What is this function doing: mmks_updatePSOForm(loPSOFormStoreBO)


By dgsoft - 7/22/2009

Also.. one comment.. If I remove transaction.. code does not call any error. and data saves.. Unsure
By dgsoft - 7/22/2009

Its just to set values for BO properties



Private Sub mmks_updatePSOForm(ByVal toBO As PSOFormStoreBO)



Dim lcXformXML As String = ""

If Me.FileUploadXForm.HasFile() = True Then

Dim loStreadReader As StreamReader = New StreamReader(Me.FileUploadXForm.PostedFile.InputStream)

lcXformXML = loStreadReader.ReadToEnd()

End If



toBO.filename = Me.PSOForm_filename.Text

toBO.formsetid = Me.PSOForm_formsetid.Text

toBO.validForm = Me.PSOForm_validFrom.Value

toBO.validto = Me.PSOForm_validTo.Value

toBO.papersize = Me.PSOForm_Papersize.Value

toBO.topage = Me.PSOForm_topage.Value

toBO.frompage = Me.PSOForm_fromPage.Value

toBO.comment = Me.PSOForm_HtmlEditor1.Text



If Not String.IsNullOrEmpty(lcXformXML) Then

toBO.xformxml = lcXformXML

End If





End Sub
By dgsoft - 7/22/2009

This is complete method code



In my case llNewUser = .F. and pmks_form_id has correct integer value



_

Public Function mmks_save() As String

Dim lcErrorMessage As String = "SUCCESS"

Dim llNewUser As Boolean = pmks_form_Id < 0

Dim lSaveResult As MicroFour.StrataFrame.Data.SaveUndoResult

Dim lcUploadErrorMessage As String = ""

Dim loPSOFormStoreBO As PSOFormStoreBO = New PSOFormStoreBO()

If llNewUser Then

loPSOFormStoreBO.Add()

Else

loPSOFormStoreBO.FillByPrimaryKey(pmks_form_Id)

End If



If Me.FileUploadPng.HasFile() = True Then

Dim lcFormName As String = Me.PSOForm_filename.Text

Dim lcFormStem As String = ""

If lcFormName.IndexOf(".") > 0 Then

Dim lcFormStems As String() = lcFormName.Split(".")

lcFormStem = lcFormStems(0)

Else

lcFormStem = lcFormName

End If



If Not String.IsNullOrEmpty(lcFormStem) Then

Dim rootpath As String = Server.MapPath("~/")

Dim lcMandatorPath As String = rootpath + Session("session_mandator_name") + "\"

Dim loDirectoryInfo As DirectoryInfo = New DirectoryInfo(lcMandatorPath)

If Not loDirectoryInfo.Exists() Then

loDirectoryInfo.Create()

End If

Dim lcFormPath As String = lcMandatorPath + lcFormStem + "\"

loDirectoryInfo = New DirectoryInfo(lcFormPath)

If Not loDirectoryInfo.Exists() Then

loDirectoryInfo.Create()

End If

Try

Me.FileUploadPng.PostedFile.SaveAs(lcFormPath + Path.GetFileName(Me.FileUploadPng.FileName))

Catch ex As Exception

lcUploadErrorMessage = ex.Message

End Try



End If



End If







Try

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

mmks_updatePSOForm(loPSOFormStoreBO)



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

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

BusinessLayer.TransactionCommit("PENSOLUTIONOFFICE", "PENSOLUTIONOFFICE")

lcErrorMessage = "SUCCESS"

Else

Throw New Exception("An error happen during save data!")

End If

Catch ex As Exception

lcErrorMessage = ex.Message

BusinessLayer.TransactionRollback("PENSOLUTIONOFFICE", "PENSOLUTIONOFFICE")

End Try

Return (lcErrorMessage)

End Function
By dgsoft - 7/22/2009

Sorry.. I copy wrong code Smile)))







_

Public Function mmks_save() As String

Dim lcErrorMessage As String = "SUCCESS"

Dim lcTransactionKey As String = Guid.NewGuid().ToString()

Dim llNewUser As Boolean = pmks_form_Id < 0

Dim lSaveResult As MicroFour.StrataFrame.Data.SaveUndoResult

Dim lcUploadErrorMessage As String = ""

Dim loPSOFormStoreBO As PSOFormStoreBO = New PSOFormStoreBO()

If llNewUser Then

loPSOFormStoreBO.Add()

Else

loPSOFormStoreBO.FillByPrimaryKey(pmks_form_Id)

End If



If Me.FileUploadPng.HasFile() = True Then

Dim lcFormName As String = Me.PSOForm_filename.Text

Dim lcFormStem As String = ""

If lcFormName.IndexOf(".") > 0 Then

Dim lcFormStems As String() = lcFormName.Split(".")

lcFormStem = lcFormStems(0)

Else

lcFormStem = lcFormName

End If



If Not String.IsNullOrEmpty(lcFormStem) Then

Dim rootpath As String = Server.MapPath("~/")

Dim lcMandatorPath As String = rootpath + Session("session_mandator_name") + "\"

Dim loDirectoryInfo As DirectoryInfo = New DirectoryInfo(lcMandatorPath)

If Not loDirectoryInfo.Exists() Then

loDirectoryInfo.Create()

End If

Dim lcFormPath As String = lcMandatorPath + lcFormStem + "\"

loDirectoryInfo = New DirectoryInfo(lcFormPath)

If Not loDirectoryInfo.Exists() Then

loDirectoryInfo.Create()

End If

Try

Me.FileUploadPng.PostedFile.SaveAs(lcFormPath + Path.GetFileName(Me.FileUploadPng.FileName))

Catch ex As Exception

lcUploadErrorMessage = ex.Message

End Try



End If



End If







Try

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

mmks_updatePSOForm(loPSOFormStoreBO)

MicroFour.StrataFrame.Data.DataBasics.DataSources("PENSOLUTIONOFFICE").SetDebugOn("c:\DebugFile.html", True)

lSaveResult = loPSOFormStoreBO.Save(True, lcTransactionKey)

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

BusinessLayer.TransactionCommit("PENSOLUTIONOFFICE", lcTransactionKey)

lcErrorMessage = "SUCCESS"

Else

Throw New Exception("An error happen during save data!")

End If

Catch ex As Exception

lcErrorMessage = ex.Message

BusinessLayer.TransactionRollback("PENSOLUTIONOFFICE", lcTransactionKey)

End Try

Return (lcErrorMessage)



By Edhy Rijo - 7/22/2009

I really don't see anything wrong, so at this point is just to try and error unless Trent or somebody else have another suggestion.



Try moving the code mmks_updatePSOForm(loPSOFormStoreBO) before the TransactionBegin...





mmks_updatePSOForm(loPSOFormStoreBO)

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




By dgsoft - 7/22/2009

Now I get closer to my problem..



Please look...

[code]

Try

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

''' ************************************************************************************

''' HERE I UPDATE BUSINESS OBJECT PROPERTIES mmks_updatePSOForm(loPSOFormStoreBO)

''' IF I UPDATE ONE or ANY PROPERTIES OF BO - then SAVE() works perfect but TransactionCommit - FAIL

'' IF I DO NOT UPDATE ANY PROPERTIES OF BO - then TransactionCommit SUCCESS!!!!!

''' *************************************************************************************

MicroFour.StrataFrame.Data.DataBasics.DataSources("PENSOLUTIONOFFICE").SetDebugOn("c:\DebugFile.html", True)

lSaveResult = loPSOFormStoreBO.Save(True, lcTransactionKey)

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

BusinessLayer.TransactionCommit("PENSOLUTIONOFFICE", lcTransactionKey)

lcErrorMessage = "SUCCESS"

Else

Throw New Exception("An error happen during save data!")

End If

Catch ex As Exception

lcErrorMessage = ex.Message

BusinessLayer.TransactionRollback("PENSOLUTIONOFFICE", lcTransactionKey)

End Try

[code]



The diffrence between developer machine and customer machine where I currently debug it with Visual Studio..



on development machine I have included PenSolutionOfficeBO as Project.. but

on customer machine - its only DLL which located in BIN folder.



So.. any ideas now?



Thanks!
By dgsoft - 7/22/2009

Please look my last comment.. I thinking I localize the problem untill one line of code Smile
By Edhy Rijo - 7/22/2009

Good, so the problem is here:



Private Sub mmks_updatePSOForm(ByVal toBO As PSOFormStoreBO)



Dim lcXformXML As String = ""

If Me.FileUploadXForm.HasFile() = True Then

Dim loStreadReader As StreamReader = New StreamReader(Me.FileUploadXForm.PostedFile.InputStream)

lcXformXML = loStreadReader.ReadToEnd()

End If



toBO.filename = Me.PSOForm_filename.Text

toBO.formsetid = Me.PSOForm_formsetid.Text

toBO.validForm = Me.PSOForm_validFrom.Value

toBO.validto = Me.PSOForm_validTo.Value

toBO.papersize = Me.PSOForm_Papersize.Value

toBO.topage = Me.PSOForm_topage.Value

toBO.frompage = Me.PSOForm_fromPage.Value

toBO.comment = Me.PSOForm_HtmlEditor1.Text



If Not String.IsNullOrEmpty(lcXformXML) Then

toBO.xformxml = lcXformXML

End If



End Sub





As I understand it you are sending your BO as toBO to update some properties. Did you try calling mmks_updatePSOForm() before TransactionBeign...?
By dgsoft - 7/22/2009

Yes.

Even if I leave only one line for update

toBO.filename = Me.PSOForm_filename.Text



TransactionCommit fail in any case..



Yes. I change order of lines and try update befor TransactionBegin.. it does not help...

For this business object I use RowVersionOrTimestampColumn - timestamp

UpdateConcurrencyType - OptimisticTimestamp
By Edhy Rijo - 7/22/2009

This quote is from the "Using Transactional Processing" topic in the SF help file:

Transaction processing is often used to implement pessimistic concurrency. Database tables participating in the transaction can be locked, depending on the IsolationLevel used when the transaction was started. This prevents client applications other than the transaction owner from modifying the tables while the transaction is processing.




Since you are using ReadCommitted Isolation Level and then modifying the BO properties, then the transaction triggers an error. I believe you have two options here:

1-Move mmks_updatePSOForm() before TransactionBeign

2-Change the Isolation Level to ReadUncommitted



Also check this KB: http://msdn.microsoft.com/en-us/library/ms173763.aspx



Try boths and let me know.


By dgsoft - 7/22/2009

I made so

mmks_updatePSOForm(loPSOFormStoreBO)

BusinessLayer.TransactionBegin("PENSOLUTIONOFFICE", lcTransactionKey, Data.IsolationLevel.ReadUncommitted)



and have no success.. same error.. about transaction end and can't be used..



I give up for today.. now is 01:19 am in Moscow Smile Maybe morning bring something Smile

Thanks for your help!

See ya!

Denis
By dgsoft - 7/22/2009

This is error message details..

Transaction still does not work. I had restart a SQL Server.

What is ZombieCheck is?
By dgsoft - 7/22/2009

Just idea

Maybe the code close the connection without completing the Transact-SQL transaction.

So.. I use business object in separate dll and transactionBegin and TransactionCommit in aspx file. Is there on BO.Save() connection is closed? and then.. Transaction is no more control a connection.. or?

Or I request another connection and receive the previous connection from the connection pool.. so its seems also possible...



Please any ideas
By dgsoft - 7/22/2009

And the last idea what I have...

When I made BO.SAVE() - because BO has timestamp - then after changes commited, BusinessObject make FILL to refresh new timestamp.. and FILL close connection.. and - seems then TransactionCommit has no more mind - because connection is closed.

Of couse I use BO.SAVE(true, lcTransactionKey) - and on my developer machine I have not a problem.. - this is strange... but diffrence only.. all my business objects stored in separate DLL.. and from aspx I just reference this dll.. createobject.. and so on..

TransactionBegin - running in aspx... BO.SAVE() occurs in DLL... TransactionCommit() also in the aspx...



So.. I realy need help ... don't know what to do Sad
By Trent L. Taylor - 7/23/2009

OK, let's back up several steps and talk a little logic and maybe we can work through this.



First of all, a ZombieCheck is a piece of an SQL Transaction looking for a stale (or closed) transaction. This is intrinsic to the Sql Client, and is correct in checking. But another thing that I would like to revisit here, as there was a lot of chatter, but the thing that struck me was this: when you copied over the MDF from your development machine, it worked.



Put all of the code aside. If your code was left intact and you ran this against two different databases and it worked on the one created in your development server (MDF) and the same code failed when run against the production server, then there is most definitely a SQL side issue.



Please confirm that what I have said is accurate before I go down another path. Thanks.
By dgsoft - 7/23/2009

Hi Trent,

Thanks for response.

1) I shutdown developer SQL Server 2008 - and copy MDF file and upload to customer by FTP

2) Download MDF file and copy it to the Programme\Microsoft SQL Server\ MSSQL10.MSSQLSERVER\MSSQL\DATA on customer side

3) Attach database to customer SQL Server 2008

4) On Developer SQL Server - no problem. All works as expect

5) On customer side problems begins with Error message

A transaction with the key [PENSOLUTIONOFFICE] is already started. (at this time I used same name for all transactions.. and I thought during my code one transaction begins and not finished with rollback or commit.. probably crush or cancel debugging

6) Then I change my code and began generate unique GUID string as key for all new transactions.

7) Then I have error message about transaction is closed and can't be used.

8) Then I made for test changes.. fill business object by primary, change nothing .. Save() Commit() - all works

9) Then I change one field of BO and try Save().. Commit() - and then error happens again.



So this is what I have now.
By Trent L. Taylor - 7/23/2009

Well, you might be chasing your tail (I have been known to do that from time to time BigGrin). We store off a cache of transaction keys, so it is actually NOT recommended to use the same transaction key for different processes that could be going on at the same time. For example, if I am going to save 2 BOs on the same transaction during the same process, that is fine as I would want to use the same transaction key. However, if there is potential for there to be two separate process try to start a transaction on the same key at the same time, it will fail. So procedure could be the difference at run-time versus design-time.



One thing I might suggest is creating a sample for you to work off of that is simple so you can isolate the issue. For example, create a single table (or two if that is what your test requires) on a test database. Then create a new project, one (or two) BOs, then create a single button that creates the transaction, creates the records, and saves. If this works in both environments, then you will know exactly where your issue resides. I generally take this type of approach on errors like this so I can isolate the issue. Once isolated, it is far easier to see what is going on within the application at large.
By dgsoft - 7/23/2009

Hi,

All good what you say but then I need a StrataFrame license on cusomer side.. to buid such examples. On developer machine I have no problems without any examples.

I am currently remove all transactions from my code.. because I have realy a stress by my work.. its shortest solution already work.. and maybe in future.. I will add transactions again when I understand whats wrong.. and will have more time to play instead work.



Thanks for attention

Denis
By Edhy Rijo - 7/23/2009

dgsoft (07/23/2009)
Hi,

All good what you say but then I need a StrataFrame license on cusomer side.. to buid such examples. On developer machine I have no problems without any examples.




Hi Denis,



Trent was not suggesting you build a sample at the customer site. What I understand from his previous message is that it would be good to build another test project with just 2 tables and 2 BO so you can test on an easy to reproduce project to help you find what the issue is.



I use transactions all the time using basically the same code as yours, except that I do not make any changes to the BO properties after the transaction begins and so far have not found any problems, but that does not mean that you have a real issue here.
By Edhy Rijo - 7/23/2009

Edhy Rijo (07/23/2009)
[quote]dgsoft (07/23/2009)
... but that does not mean that you have a real issue here.




Sorry this should have read:

... but that does not mean that you don't have a real issue here. Hehe
By Trent L. Taylor - 7/23/2009

What Edhy mentioned is exactly what I was getting at. There is no reason to do this on the customers site. I am suggesting that you build a simple EXE that you can run and test against. This is how I isolate problems within my code as well.