Base solution for your next web application
Open Closed

getting This SqlTransaction has completed; it is no longer usable. #11035


User avatar
0
shedspotter created

What is your product version? 11.0.0

What is your product type (Angular or MVC)? Angular

What is product framework type (.net framework or .net core)? .NET 6

Hi, I am getting below exception while calling the api and there is some strange thing is happing , same API is working fine in our staging env, prod env and even in mobile as well but not in our development env. in development env we are getting below exception and also the api which we are calling is getting data from store procedure

System.InvalidOperationException: This SqlTransaction has completed; it is no longer usable. at Microsoft.Data.SqlClient.SqlTransaction.ZombieCheck() at Microsoft.Data.SqlClient.SqlTransaction.Commit() at Microsoft.EntityFrameworkCore.Storage.RelationalTransaction.Commit() at Abp.EntityFrameworkCore.Uow.DbContextEfCoreTransactionStrategy.Commit() at Abp.EntityFrameworkCore.Uow.EfCoreUnitOfWork.CommitTransaction() at Abp.EntityFrameworkCore.Uow.EfCoreUnitOfWork.CompleteUowAsync() at Abp.Domain.Uow.UnitOfWorkBase.CompleteAsync() at Abp.AspNetCore.Mvc.Uow.AbpUowActionFilter.OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)

Thanks


3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @shedspotter

    Could you share the method causing this problem ?

    Thanks,

  • User Avatar
    0
    shedspotter created

    public async Task<List<BoardMyTaskDto>> GetMyTasksByPage(long userId, bool showSubtask, long pageIndex, long pageSize, long? parentTaskId) { EnsureConnectionOpen();

            using (var command = CreateCommand("GetMayTasksByPage", CommandType.StoredProcedure,
                new SqlParameter("@userId", userId),
                new SqlParameter("@showSubTask", showSubtask),
                new SqlParameter("@pageIndex", pageIndex),
                new SqlParameter("@pageSize", pageSize),
                new SqlParameter("@parentTask", parentTaskId)
                ))
            {
                var result = new List&lt;BoardMyTaskDto&gt;();
    
                using (var dataReader = await command.ExecuteReaderAsync())
                {
                    if (dataReader.HasRows)
                    {
                        try
                        {
                            result = (from record in dataReader.Cast&lt;DbDataRecord&gt;()
                                      select new
                                      {
                                          GroupId = record.GetValue(0) == DBNull.Value ? 0 : record.GetInt64(0),
                                          TaskId = record.GetValue(1) == DBNull.Value ? 0 : record.GetInt64(1),
                                          Tasks = record.GetValue(2) == DBNull.Value ? null : record.GetString(2),
                                          TaskPosition = record.GetValue(3) == DBNull.Value ? 0 : record.GetDouble(3),
                                          ColumnDataId = record.GetValue(4) == DBNull.Value ? 0 : record.GetInt64(4),
                                          Value = record.GetValue(5) == DBNull.Value ? null : record.GetString(5),
                                          BoardColumnId = record.GetValue(6) == DBNull.Value ? 0 : record.GetInt64(6),
                                          UserId = record.GetValue(7) == DBNull.Value ? 0 : record.GetInt64(7),
                                          UName = record.GetValue(8) == DBNull.Value ? null : record.GetString(8),
                                          SurName = record.GetValue(9) == DBNull.Value ? null : record.GetString(9),
                                          ProfilePictureId = record.GetValue(10) == DBNull.Value ? Guid.Empty : record.GetGuid(10),
                                          TenantId = record.GetValue(11) == DBNull.Value ? 0 : record.GetInt32(11),
                                          TagId = record.GetValue(12) == DBNull.Value ? 0 : record.GetInt64(12),
                                          TagName = record.GetValue(13) == DBNull.Value ? null : record.GetString(13),
                                          TagColorCode = record.GetValue(14) == DBNull.Value ? null : record.GetString(14),
                                          LabelId = record.GetValue(15) == DBNull.Value ? 0 : record.GetInt64(15),
                                          LabelName = record.GetValue(16) == DBNull.Value ? null : record.GetString(16),
                                          LabelColorCode = record.GetValue(17) == DBNull.Value ? null : record.GetString(17),
                                          LabelType = record.GetValue(18) == DBNull.Value ? null : record.GetString(18),
                                          LinkName = record.GetValue(19) == DBNull.Value ? null : record.GetString(19),
                                          LinkUrl = record.GetValue(20) == DBNull.Value ? null : record.GetString(20),
                                          Code1 = record.GetValue(21) == DBNull.Value ? null : record.GetString(21),
                                          Code2 = record.GetValue(22) == DBNull.Value ? null : record.GetString(22),
                                          Code3 = record.GetValue(23) == DBNull.Value ? null : record.GetString(23),
                                          Code4 = record.GetValue(24) == DBNull.Value ? null : record.GetString(24),
                                          Code5 = record.GetValue(25) == DBNull.Value ? null : record.GetString(25),
                                          Code6 = record.GetValue(26) == DBNull.Value ? null : record.GetString(26),
                                          Phone1 = record.GetValue(27) == DBNull.Value ? null : record.GetString(27),
                                          Phone2 = record.GetValue(28) == DBNull.Value ? null : record.GetString(28),
                                          Phone3 = record.GetValue(29) == DBNull.Value ? null : record.GetString(29),
                                          Phone4 = record.GetValue(30) == DBNull.Value ? null : record.GetString(30),
                                          Phone5 = record.GetValue(31) == DBNull.Value ? null : record.GetString(31),
                                          Phone6 = record.GetValue(32) == DBNull.Value ? null : record.GetString(32),
                                          Address1 = record.GetValue(33) == DBNull.Value ? null : record.GetString(33),
                                          Address2 = record.GetValue(34) == DBNull.Value ? null : record.GetString(34),
                                          Country = record.GetValue(35) == DBNull.Value ? null : record.GetString(35),
                                          State = record.GetValue(36) == DBNull.Value ? null : record.GetString(36),
                                          Latitude = record.GetValue(37) == DBNull.Value ? null : record.GetString(37),
                                          Longitude = record.GetValue(38) == DBNull.Value ? null : record.GetString(38),
                                          Description = record.GetValue(41) == DBNull.Value ? null : record.GetString(41),
                                          ParentTaskId = record.GetValue(42) == DBNull.Value ? 0 : record.GetInt64(42),
                                          BoardId = record.GetValue(43) == DBNull.Value ? 0 : record.GetInt64(43),
                                          BoardName = record.GetValue(44) == DBNull.Value ? null : record.GetString(44),
                                          ColumnType = record.GetValue(45) == DBNull.Value ? null : record.GetString(45),
                                          GroupName = record.GetValue(46) == DBNull.Value ? null : record.GetString(46),
                                          GroupColorCode = record.GetValue(47) == DBNull.Value ? null : record.GetString(47),
                                          AnchorText = record.GetValue(48) == DBNull.Value ? null : record.GetString(48)
                                      }).GroupBy(e => new { e.TaskId, e.Tasks, e.TaskPosition, e.GroupId, e.Description, e.ParentTaskId })
                        .Select(
                                  e => new BoardMyTaskDto
                                  {
                                      Id = e.Key.TaskId,
                                      Tasks = e.Key.Tasks,
                                      GroupId = e.Key.GroupId,
                                      Position = e.Key.TaskPosition,
                                      Description = e.Key.Description,
                                      ParentTaskId = e.Key.ParentTaskId,
                                      ColumnType = e.FirstOrDefault().ColumnType,
                                      BoardName = e.FirstOrDefault().BoardName,
                                      BoardId = e.FirstOrDefault().BoardId,
                                      Group = new Group()
                                      {
                                          ColorCode = e.FirstOrDefault(x => x.GroupColorCode != null).GroupColorCode,
                                          Name = e.FirstOrDefault(x => x.GroupName != null).GroupName,
                                          Id = e.Key.GroupId,
                                          BoardId = e.FirstOrDefault(x => x.BoardId != 0).BoardId,
                                          BoardName = e.FirstOrDefault(x => x.BoardName != null).BoardName
                                      },
                                      TaskData = e.Where(x => x.BoardColumnId != 0).GroupBy(t => new { t.TaskId, t.BoardColumnId, t.ColumnType }).Select(t => new CustomColumns
                                      {
                                          Id = t.Key.BoardColumnId,
                                          Type = t.Key.ColumnType,
                                          Value = t.Select(x => x.Value).FirstOrDefault(),
                                          Label = (t.Select(x => x.LabelId).FirstOrDefault() > 0) ? new Labels.Label
                                          {
                                              Id = t.Select(x => x.LabelId).FirstOrDefault(),
                                              ColorCode = t.Select(x => x.LabelColorCode).FirstOrDefault(),
                                              Name = t.Select(x => x.LabelName).FirstOrDefault(),
                                              Type = t.Select(x => x.LabelType).FirstOrDefault(),
                                              AnchorText = (t.Select(x => x.AnchorText).FirstOrDefault()) == null ? string.Empty : t.Select(x => x.AnchorText).FirstOrDefault()
                                          } : null,
                                          Link = (t.Select(x => x.LinkName).FirstOrDefault() == null) ? null : new Link
                                          {
                                              Name = t.Select(x => x.LinkName).FirstOrDefault(),
                                              Url = t.Select(x => x.LinkUrl).FirstOrDefault()
                                          },
                                          Phone =null,
                                          Location = null,
                                          Tag = null,
                                          User =: null,
                                      }).ToList()
    
                                  }).ToList();
                        }
                        catch (Exception ex)
                        {
                            throw;
                        }
                    }
    
                }
                return result;
            }
        }
    
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @shedspotter

    This doesn't seem to related to AspNet Zero. However, you can check if you are using any sync method in this method instead of using async version of it.

    Using sync over async might cause such a problem.