Parallel transactions and entity framework

Posted on 2011-10-30
Last Modified: 2012-05-12
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?
Question by:fantamen
    LVL 40

    Accepted Solution

    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;

    Author Comment

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

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    In my previous article ( we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
    More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now