Link to home
Start Free TrialLog in
Avatar of fantamen
fantamenFlag for Italy

asked on

Parallel transactions and entity framework

I've a web service used to append data from source A (company ERP) to source B (sql production database). Web Service can be invoked n times.
Sometimes an exception occured: System.InvalidOperationException: SqlConnection not support parallel transaction and the specific code area where I suppose is located the problem is this sub:

 Friend Sub Aggiungi_AnaCarichi()
        Dim NuovoPianoCarico As New AnaCarichi
        With NuovoPianoCarico
            .NumPianoCarico = _NumPianoCarico
            .DataCarico = _DataCarico
            .DataElaborazione = Date.Now
            .Descrizione = _Descrizione
            .IDStato_PCarico = "0"
        End With
        dbLineProdContext.AddToAnaCarichi(NuovoPianoCarico)
        Try
            dbLineProdContext.SaveChanges()
            ' Salvo il valore della colonna identity IDPianoCarico, mi servirà quando dovrò salvare
            ' i dati in Carichi_Padri, Carichi_PadriVarianti e Carichi_Figli.
            _IDPianoCarico = NuovoPianoCarico.IDPianoCarico
        Catch ex2 As OptimisticConcurrencyException
            dbLineProdContext.Refresh(Objects.RefreshMode.ClientWins, dbLineProdContext.AnaCarichi)
            dbLineProdContext.SaveChanges()
            _IDPianoCarico = NuovoPianoCarico.IDPianoCarico
        Catch ex3 As UpdateException
            pvclErrori.Codice = 1
            pvclErrori.Descrizione &= "Salvataggio nuovo p.d.c. in AnaCarichi: " & ex3.Message & vbCrLf
        End Try
    End Sub

I use entity framework. AnaCarichi is an entity of the entity model dbLineProdContext.
What can I do to solve the problem?
ASKER CERTIFIED SOLUTION
Avatar of Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger)
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fantamen

ASKER

I've read something about this property. I'll follow your suggestion and then I'll inform you.