This is a migrated thread and some comments may be shown as answers.

SqlConnection does not support parallel transactions - how to avoid

3 Answers 1261 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Robert
Top achievements
Rank 2
Robert asked on 10 Aug 2010, 09:36 AM
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

3 Answers, 1 is accepted

Sort by
0
Serge
Telerik team
answered on 11 Aug 2010, 02:45 PM
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
0
Robert
Top achievements
Rank 2
answered on 17 Aug 2010, 01:51 PM
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
0
Serge
Telerik team
answered on 19 Aug 2010, 04:44 PM
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
Tags
Development (API, general questions)
Asked by
Robert
Top achievements
Rank 2
Answers by
Serge
Telerik team
Robert
Top achievements
Rank 2
Share this question
or