Page 1 of 1
Transaction
Posted: Tue 07 Jun 2011 14:25
by Zero-G.
Hey
Can you please post a VB.NET sample where you show, how to use the new Transaction property from the DataContext.
THX
Posted: Wed 08 Jun 2011 16:47
by StanislavK
Please refer to the 'Transactions' topic in our documentation:
http://www.devart.com/linqconnect/docs/ ... tions.html
Feel free to contact us if you encounter any problems with this sample, or need some other information concerning transactions in LinqConnect.
Posted: Thu 09 Jun 2011 10:48
by Zero-G.
Hey
Thanks for your information.
I am using the following code to save changes to my DataContext.
Code: Select all
Dim sConnection = myContext.MaxUsedConnections
myContext.MaxUsedConnections = 1
myContext.Connection.Open()
myContext.Transaction = myContext.Connection.BeginTransaction
Try
myContext.Log = Console.Out
myContext.SubmitChanges(System.Data.Linq.ConflictMode.FailOnFirstConflict)
myContext.Transaction.Commit()
Catch ex As Exception
myContext.Transaction.Rollback()
If myContext.Connection.State = ConnectionState.Open Then
myContext.Connection.Close()
End If
Start.WriteToErrorLog(ex.Message.ToString, ex.InnerException.ToString, ex.StackTrace.ToString, MessageCaption, "Automatisch - Beim Speichern")
Dim Nochmal = IntelliSoft.myMessageBox.OfficeBox.Show(String.Format("Beim Speichern der Daten ist ein " & _
"Fehler aufgetreten!{0}Fehler: " & _
"{1}{0}Details: {2}{0}Noch einmal " & _
"probieren?", Environment.NewLine, _
ex.Message, ex.InnerException), _
MessageCaption, MessageBoxButtons.YesNo, _
IntelliSoft.myMessageBox.OfficeMessageBoxIcon.Error)
If Nochmal = DialogResult.Yes Then
Dim DidItNow As Boolean = SaveDataContext(myContext)
Return DidItNow
Else
myContext.RejectChanges()
End If
End Try
If myContext.Connection.State = ConnectionState.Open Then
myContext.Connection.Close()
End If
myContext.MaxUsedConnections = sConnection
But I get the following error:
Local transaction can not be started while in a distributed transaction
Thx for advise
Posted: Fri 10 Jun 2011 13:59
by StanislavK
As far as I can understand, you are executing this code inside a
TransactionScope environment. Please tell us if I am correct. If yes, this is the designed behaviour: in case a local transaction could be started inside the scope of a distributed one, the latter cannot keep data integrity. For example, if the local transaction is committed, the distributed one cannot roll back these changes.
Posted: Fri 10 Jun 2011 14:07
by Zero-G.
Hey
No, I don't run this in an transaction scope.
This is the code, how I want to save my DataContext's change.
Posted: Tue 14 Jun 2011 15:47
by StanislavK
I will send you a test project in a letter, please check that it is not blocked by your mail filter.
Please specify if the problem occurs with this project as well. If no, please describe what should be changed to reproduce the issue.