• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1716
  • Last Modified:

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?
1 Solution
Jacques Bourgeois (James Burger)Commented:
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.

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now