Open Closed

This SqlTransaction has completed; It is no longer usable #6253


0
GSOFT created

I'm not sure where to post this question, but I got a trouble without any clue. When I update I received a message "Internal error", but data is still saved. I try to debug and this happen. image.png

public async Task<SysError> UpdateAssGroup(CreateOrEditAssGroupDto input)
        {
            try
            {
                    string GROUP_ID = input.GROUP_ID;
					string TYPE_ID =  input.TYPE_ID;			
					string GROUP_CODE =  input.GROUP_CODE;					
					string GROUP_NAME =  input.GROUP_NAME;					
					string PARENT_ID =  input.PARENT_ID;					
					string IS_LEAF =  input.IS_LEAF;					
					int? GROUP_LEVEL =  input.GROUP_LEVEL;					
					string ASS_CAT =  input.ASS_CAT;					
					string AMORT_ACCTNO =  input.AMORT_ACCTNO;					
					string EXP_ACCTNO =  input.EXP_ACCTNO;					
					string INC_ACCTNO =  input.INC_ACCTNO;					
					string LIQ_ACCTNO =  input.LIQ_ACCTNO;					
					string ASSET_ACCTNO =  input.ASSET_ACCTNO;					
					string ASSET_ACCTNO_NHNN =  input.ASSET_ACCTNO_NHNN;					
					int? AMORT_MONTH =  input.AMORT_MONTH;					
					decimal? AMORT_RATE =  input.AMORT_RATE;					
					string NOTES =  input.NOTES;					
					string RECORD_STATUS =  input.RECORD_STATUS;					
					string AUTH_STATUS =  input.AUTH_STATUS;					
					string MAKER_ID =  input.MAKER_ID;					
					string CREATE_DT = null;
					if (input.CREATE_DT != null)
					{
						CREATE_DT = DateTime.Parse(input.CREATE_DT.ToString()).ToString(formatDate);
					}					
					string CHECKER_ID =  input.CHECKER_ID;					
					string APPROVE_DT = null;
					if (input.APPROVE_DT != null)
					{
						APPROVE_DT = DateTime.Parse(input.APPROVE_DT.ToString()).ToString(formatDate);
					}				

                var result = await Context.Query<SysError>().FromSql($"EXEC ASS_GROUP_Upd @p_GROUP_ID={GROUP_ID}, @p_TYPE_ID={TYPE_ID}, @p_GROUP_CODE={GROUP_CODE}, @p_GROUP_NAME={GROUP_NAME}, @p_PARENT_ID={PARENT_ID}, @p_IS_LEAF={IS_LEAF}, @p_ASS_CAT={ASS_CAT}, @p_AMORT_ACCTNO={AMORT_ACCTNO}, @p_EXP_ACCTNO={EXP_ACCTNO}, @p_INC_ACCTNO={INC_ACCTNO}, @p_LIQ_ACCTNO={LIQ_ACCTNO}, @p_ASSET_ACCTNO={ASSET_ACCTNO}, @p_ASSET_ACCTNO_NHNN={ASSET_ACCTNO_NHNN}, @p_AMORT_MONTH={AMORT_MONTH}, @p_AMORT_RATE={AMORT_RATE}, @p_NOTES={NOTES}, @p_RECORD_STATUS={RECORD_STATUS}, @p_AUTH_STATUS={AUTH_STATUS}, @p_MAKER_ID={MAKER_ID}, @p_CREATE_DT={CREATE_DT}, @p_CHECKER_ID={CHECKER_ID}, @p_APPROVE_DT={APPROVE_DT}").FirstOrDefaultAsync();
                return result;
            }
            catch(Exception ex)
            {
                return new SysError() { ErrorDesc = ex.Message, Result = "-1" };
            }
            
        }
private async Task<SysErrorDto> Update(CreateOrEditAssGroupDto input)
        {
            try
            {
                var result = await _assGroupRepository.UpdateAssGroup(input);

                return ObjectMapper.Map<SysErrorDto>(result);
            }
            catch (Exception)
            {
                return null;
            }
        }
public async Task<SysErrorDto> CreateOrEdit(CreateOrEditAssGroupDto input)
        {
            try
            {
                if (input.GROUP_ID.IsNullOrWhiteSpace())
                {
                    return await Create(input);
                }
                else
                {
                    return await Update(input);
                }
            }
            catch (Exception)
            {
                return null;
            }
        }

I got "This SqlTransaction has completed; It is no longer usable" when I jump to return await Update(input). Is my query wrong? Or Is there a way I can pass this problem?


9 Answer(s)
  • 0
    maliming created

    Please share the StackTrace information in the above image.

  • 0
    GSOFT created

    Hi @maliming, Do you mean call stack? image.png

  • 0
    maliming created

    image.png

  • 0
    GSOFT created
    		StackTrace	"   at System.Data.SqlClient.SqlTransaction.ZombieCheck()\r\n   at System.Data.SqlClient.SqlTransaction.Commit()\r\n   at Microsoft.EntityFrameworkCore.Storage.RelationalTransaction.Commit()\r\n   at Abp.EntityFrameworkCore.Uow.DbContextEfCoreTransactionStrategy.Commit() in D:\\Github\\aspnetboilerplate\\src\\Abp.EntityFrameworkCore\\EntityFrameworkCore\\Uow\\DbContextEfCoreTransactionStrategy.cs:line 66\r\n   at Abp.EntityFrameworkCore.Uow.EfCoreUnitOfWork.CommitTransaction() in D:\\Github\\aspnetboilerplate\\src\\Abp.EntityFrameworkCore\\EntityFrameworkCore\\Uow\\EfCoreUnitOfWork.cs:line 92\r\n   at Abp.EntityFrameworkCore.Uow.EfCoreUnitOfWork.CompleteUowAsync() in D:\\Github\\aspnetboilerplate\\src\\Abp.EntityFrameworkCore\\EntityFrameworkCore\\Uow\\EfCoreUnitOfWork.cs:line 83\r\n   at Abp.Domain.Uow.UnitOfWorkBase.CompleteAsync() in D:\\Github\\aspnetboilerplate\\src\\Abp\\Domain\\Uow\\UnitOfWorkBase.cs:line 273\r\n   at Abp.AspNetCore.Mvc.Uow.AbpUowActionFilter.OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) in D:\\Github\\aspnetboilerplate\\src\\Abp.AspNetCore\\AspNetCore\\Mvc\\Uow\\AbpUowActionFilter.cs:line 49\r\n   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()"	string
    
    

    image.png Hope it helpful

  • 0
    alper created

    you are using Context.Query<SysError>() which is not covered in UnitOfWork. That's why it's being saved.

  • 0
    GSOFT created

    Hi @alper I do not work on UOW. I don't think It is problem.

  • 0
    ismcagdas created

    Is SysError an entity ? If so, could you share it ?

  • 0
    GSOFT created

    ^

    public class SysError
        {
            public string Result { get; set; }
    
            public string ErrorDesc { get; set; }
        }
    

    All the previous functions works stably, I think the commit and rollback point is placed wrong

  • 0
    ismcagdas created

    We couldn't reproduce this problem on our side. If you can share your project via email with info@aspnetzero.com we can try to work on your project.

    If you are willing to share your project, please also share steps to reproduce this problem.