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
            ' 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)
            _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?
Who is Participating?
Jacques Bourgeois (James Burger)Connect With a Mentor PresidentCommented:
By default, a SqlConnection cannot execute 2 commands at the same time.

To go over this limitation, you need to be in SQL Server 2005 or later and add the following to the ConnectionString: MultipleActiveResultSets=True;
fantamenAuthor Commented:
I've read something about this property. I'll follow your suggestion and then I'll inform you.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.