SqlConnection does not support parallel transactions - how to avoid

4 posts, 0 answers
  1. Robert
    Robert avatar
    21 posts
    Member since:
    Feb 2009

    Posted 10 Aug 2010 Link to this post

    Hello,
    I'm having this error appearing quite often in my webpage. I use scope per request approach and I have also set Multithreaded option to True, but still this error occurs. What is the cause of this? Should I switch to domain model, could this help?

    Sometimes I'm also getting following error: 
    Telerik.OpenAccess.RT.sql.SQLException: The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION.
       at Telerik.OpenAccess.RT.Adonet2Generic.Impl.ConnectionImp.commit()
       at OpenAccessRuntime.Relational.conn.LoggingConnection.commit()
       at OpenAccessRuntime.Relational.conn.PooledConnection.commit()
       at OpenAccessRuntime.Relational.RelationalStorageManager.finishRead(StatesReturned container, RelationalCompiledQuery cq, Object[] param, CachedQueryResult queryData, Int32 queryResultCount)

    I start new transaction in beginning of each request and commit it in end of request:

     void Application_BeginRequest(object sender, EventArgs e)
        {
            //create scope
            var scope = DataManager.ObjectScopeProvider1.GetPerRequestScope(HttpContext.Current);
            HttpContext.Current.Items["ObjectScope"] = scope;
            Data.Instance.UpdateContext(scope);
            scope.Transaction.Begin();
         
        }
    void Application_EndRequest(object sender, EventArgs e)
    {
            Telerik.OpenAccess.IObjectScope scope = (Telerik.OpenAccess.IObjectScope)HttpContext.Current.Items["ObjectScope"];
            if (scope != null)
            {
                if (scope.Transaction.IsActive)
                    scope.Transaction.Commit();
                scope.Dispose();
                HttpContext.Current.Items.Remove("ObjectScope");
            }
    }


    Thanks,
    Robert
  2. Serge
    Admin
    Serge avatar
    375 posts

    Posted 11 Aug 2010 Link to this post

    Hello Robert,

     This might be caused by one of two things. Either you have a transaction commit somewhere in the code that is called prior to the EndRequest event being fired or the BeginRequest is not being fired (this can be caused by many things).

    In order to fix the latter you have to not depend on the begin request for initializing your scope. You can either initialize in the pages or implement a custom HttpModule. We have a knowledge base article that describes how to do that. You can find it here. Please note that both the knowledge base article and code library are implemented using the new domain model approach. I will attach the code library implemented with the scope here. Note that you might have to update the references in the project in order to compile it.

    I hope this helps. Please contact us back if you face further trouble.

    All the best,
    Serge
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. Robert
    Robert avatar
    21 posts
    Member since:
    Feb 2009

    Posted 17 Aug 2010 Link to this post

    Hello,

    thanks for answer. The problem was caused by bad design. I tried to be too 'clever' and have created singleton class for data access. The static instance was shared between requests and the scope was overwritten with each request, resulting into parallel transactions and 'scope already diposed' errors.

    This link helped me to realize what is wrong:

    http://stackoverflow.com/questions/194999/are-static-class-instances-unique-to-a-request-or-a-server-in-asp-net

    Hope it helps someone else.

    Best regards,
    Robert
  5. Serge
    Admin
    Serge avatar
    375 posts

    Posted 19 Aug 2010 Link to this post

    Hi Robert,

     Thank you for sharing this resource, we will take in into account when we face customers will similar issues.

    I am glad you have resolved your issue. Do not hesitate to contact us back if you face further trouble.

    Sincerely yours,
    Serge
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top