ASP.NET Web Forms and MySql Entity Framework: "Nested Transactions Not Supported"

I have an ASP.NET web form application using the .Net Connector for MySql Entity Framework.

In the past, I have been building a web application using MySql and have never encountered this problem.

Currently, I get ~ 20,000 page views per day, and every day about 10 errors "Nested transactions are not supported."

I cannot understand why this happens at all, and why this happens only once after a while.

On the main page of the Preload event, I get the integer identifier for the user and save it in a public variable:

using (var entity = new Entities())
                {
                    var user = entity.my_aspnet_users.Single(i => i.name == Context.User.Identity.Name);
                    UserID = user.id;
                    if (HttpContext.Current.Request.Url.AbsolutePath != "###" && HttpContext.Current.Request.Url.AbsolutePath != "###")
                    {
                        if (user.Player == null)
                            Response.Redirect("###", true);
                        else
                            PlayerID = user.Player.PlayerID;
                    }
                }

And then on the page:

using (var entity = new Entities())
                            if (entity.Players.Count(i => ###) == 1)
                            {
                                var user = entity.my_aspnet_users.Single(i => i.id == Master.UserID);
                                if (user.Player == null)
                                {
                                    user.Player = entity.Players.Single(i => ###);
                                    entity.SaveChanges();
                                }
                                Response.Redirect("###", false);
                            }

SaveChanges(). , . , , .

, , , MySql? , ? MySql - 5.6.17, , - Amazon RDS.

"User.Identity.Name" ? - , ?

, :

**Exception on example code:**
System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.Data.Entity.Core.EntityException: An error occurred while starting a transaction on the provider connection. See the inner exception for details. ---> System.InvalidOperationException: Nested transactions are not supported.

at MySql.Data.MySqlClient.ExceptionInterceptor.Throw(Exception exception)

at MySql.Data.MySqlClient.MySqlConnection.Throw(Exception ex)

at MySql.Data.MySqlClient.MySqlConnection.BeginTransaction(IsolationLevel iso)

at MySql.Data.MySqlClient.MySqlConnection.BeginDbTransaction(IsolationLevel isolationLevel)

at System.Data.Common.DbConnection.BeginTransaction(IsolationLevel isolationLevel)

at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.b__0(DbConnection t, BeginTransactionInterceptionContext c)

at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)

at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.BeginTransaction(DbConnection connection, BeginTransactionInterceptionContext interceptionContext)

at System.Data.Entity.Core.EntityClient.EntityConnection.<>c__DisplayClassf.b__d()

at System.Data.Entity.Infrastructure.DefaultExecutionStrategy.Execute[TResult](Func`1 operation)

at System.Data.Entity.Core.EntityClient.EntityConnection.BeginDbTransaction(IsolationLevel isolationLevel)

--- End of inner exception stack trace ---

at System.Data.Entity.Core.EntityClient.EntityConnection.BeginDbTransaction(IsolationLevel isolationLevel)

at System.Data.Entity.Core.EntityClient.EntityConnection.BeginTransaction()

at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)

at System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions options, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction)

at System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass2a.b__27()

at System.Data.Entity.Infrastructure.DefaultExecutionStrategy.Execute[TResult](Func`1 operation)

at System.Data.Entity.Core.Objects.ObjectContext.SaveChangesInternal(SaveOptions options, Boolean executeInExistingTransaction)

at System.Data.Entity.Core.Objects.ObjectContext.SaveChanges(SaveOptions options)

at System.Data.Entity.Internal.InternalContext.SaveChanges()

at System.Data.Entity.Internal.LazyInternalContext.SaveChanges()

at System.Data.Entity.DbContext.SaveChanges()

at ###.Account.###.ButtonSubmit###_Click(Object sender, EventArgs e)

at System.Web.UI.WebControls.Button.OnClick(EventArgs e)

at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)

at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)

at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)

at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)

at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

at System.Web.UI.Page.HandleError(Exception e)

at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

at System.Web.UI.Page.ProcessRequest()

at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)

at System.Web.UI.Page.ProcessRequest(HttpContext context)

at ASP.account_###.ProcessRequest(HttpContext context)

at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()

at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)



**Exception on creating a user:**
System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.InvalidOperationException: Nested transactions are not supported.

at MySql.Data.MySqlClient.ExceptionInterceptor.Throw(Exception exception)

at MySql.Data.MySqlClient.MySqlConnection.Throw(Exception ex)

at MySql.Data.MySqlClient.MySqlConnection.BeginTransaction(IsolationLevel iso)

at MySql.Data.MySqlClient.MySqlConnection.BeginTransaction()

at MySql.Web.Security.MySQLMembershipProvider.GetUser(Object providerUserKey, Boolean userIsOnline)

at MySql.Web.Security.MySQLMembershipProvider.GetUser(String username, Boolean userIsOnline)

at MySql.Web.Security.MySQLMembershipProvider.CreateUser(String username, String password, String email, String passwordQuestion, String passwordAnswer, Boolean isApproved, Object providerUserKey, MembershipCreateStatus& status)

at System.Web.UI.WebControls.CreateUserWizard.AttemptCreateUser()

at System.Web.UI.WebControls.CreateUserWizard.OnNextButtonClick(WizardNavigationEventArgs e)

at System.Web.UI.WebControls.Wizard.OnBubbleEvent(Object source, EventArgs e)

at System.Web.UI.WebControls.CreateUserWizard.OnBubbleEvent(Object source, EventArgs e)

at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)

at System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e)

at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)

at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)

at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)

at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)

at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

at System.Web.UI.Page.HandleError(Exception e)

at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

at System.Web.UI.Page.ProcessRequest()

at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)

at System.Web.UI.Page.ProcessRequest(HttpContext context)

at ASP.register_aspx.ProcessRequest(HttpContext context)

at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()

at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
+4
1

, ​​MySQL Connector/NET.

:

  • A
  • 1 A
  • A MySQL
  • 1 .
  • B
  • 2 B
  • MySQL Connector/NET

- 4: 1 (, , , ). - , A B, . , 4 5 , , , .

, MySQL . , , Connector/NET / .

+6

All Articles