Transaction

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
Zero-G.
Posts: 398
Joined: Sat 09 Dec 2006 12:20

Transaction

Post by Zero-G. » Tue 07 Jun 2011 14:25

Hey
Can you please post a VB.NET sample where you show, how to use the new Transaction property from the DataContext.

THX

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Wed 08 Jun 2011 16:47

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.

Zero-G.
Posts: 398
Joined: Sat 09 Dec 2006 12:20

Post by Zero-G. » Thu 09 Jun 2011 10:48

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

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Fri 10 Jun 2011 13:59

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.

Zero-G.
Posts: 398
Joined: Sat 09 Dec 2006 12:20

Post by Zero-G. » Fri 10 Jun 2011 14:07

Hey

No, I don't run this in an transaction scope.

This is the code, how I want to save my DataContext's change.

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Tue 14 Jun 2011 15:47

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.

Post Reply