You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public async Task<CommonDto> GetInformation(string Id)
{
var decryptId = AesHelper.AESDecrypt(Id);
var keyName = $"GetInformation_By_{Id}";
if (!string.IsNullOrEmpty(decryptId))
{
var cacheObj = await _cacheManager.GetOrDefault(CacheHelper.CacheName.Web, keyName);
var resDto = new CommonDto();
if (cacheObj == null)
{
using (CurrentUnitOfWork.DisableFilter(AbpDataFilters.MayHaveTenant, AbpDataFilters.MustHaveTenant))
{
var infoId = Convert.ToInt64(decryptId);
var info = await _infoRepository.GetAllIncluding(m => m.CreatorUser, m => m.Material).FirstOrDefaultAsync(m => m.Id == infoId);
if (info != null)
{
resDto = new CommonDto
{
Title = info.Title,
Content = info.Material == null ? info.Summary : info.Material.Content,
CreationTime = info.CreationTime,
CreatorUserName = info.CreatorUser?.Name,
ReplyCount = info.ReplyCount,
CoverImage = info.Material?.CoverImage,
MaterialType = info.Material == null ? 0 : info.Material.MaterialType,
Url = info.Material?.Url,
Hits = info.Hits,
Upvotes = info.Upvotes,
};
await _cacheManager.SetCacheAsync(CacheHelper.CacheName.Web, keyName, resDto, null, TimeSpan.FromMinutes(10));
}
}
}
else
{
resDto = (CommonDto)cacheObj;
}
return resDto;
}
else
{
throw new UserFriendlyException("数据加载错误");
}
}
我改动后的代码:
public async Task<CommonDto> GetInformation(string Id)
{
var decryptId = AesHelper.AESDecrypt(Id);
var keyName = $"GetInformation_By_{Id}";
if (!string.IsNullOrEmpty(decryptId))
{
var cacheObj = await _cacheManager.GetOrDefault(CacheHelper.CacheName.Web, keyName);
var resDto = new CommonDto();
if (cacheObj == null)
{
using (CurrentUnitOfWork.DisableFilter(AbpDataFilters.MayHaveTenant, AbpDataFilters.MustHaveTenant))
{
var infoId = Convert.ToInt64(decryptId);
var info = await _infoRepository.GetAllIncluding(m => m.CreatorUser, m => m.Material).FirstOrDefaultAsync(m => m.Id == infoId);
if (info != null)
{
info.ExternalHits += 1;
resDto = new CommonDto
{
Title = info.Title,
Content = info.Material == null ? info.Summary : info.Material.Content,
CreationTime = info.CreationTime,
CreatorUserName = info.CreatorUser?.Name,
ReplyCount = info.ReplyCount,
CoverImage = info.Material?.CoverImage,
MaterialType = info.Material == null ? 0 : info.Material.MaterialType,
Url = info.Material?.Url,
Hits = info.Hits + info.ExternalHits,
Upvotes = info.Upvotes,
};
await _infoRepository.UpdateAsync(info);
await _cacheManager.SetCacheAsync(CacheHelper.CacheName.Web, keyName, resDto, null, TimeSpan.FromMinutes(10));
}
}
}
else
{
resDto = (CommonDto)cacheObj;
using (CurrentUnitOfWork.DisableFilter(AbpDataFilters.MayHaveTenant, AbpDataFilters.MustHaveTenant))
{
var infoId = Convert.ToInt64(decryptId);
var info = await _infoRepository.FirstOrDefaultAsync(m => m.Id == infoId);
if (info != null)
{
info.ExternalHits += 1;
await _infoRepository.UpdateAsync(info);
}
}
}
return resDto;
}
else
{
throw new UserFriendlyException("数据加载错误");
}
}
报错信息
There is already an open DataReader associated with this Connection which must be closed first.
具体如下:
INFO 2019-08-29 10:48:49,128 [12 ] ore.Mvc.Internal.ControllerActionInvoker - Executing action method Sg.SFA.Common.CommonInfoAppService.GetInformation (Sg.SFA.Application) with arguments (SooZuohyIxCVEW6MuDRwRg==) - ModelState is Valid
ERROR 2019-08-29 10:48:49,643 [23 ] Mvc.ExceptionHandling.AbpExceptionFilter - There is already an open DataReader associated with this Connection which must be closed first.
MySql.Data.MySqlClient.MySqlException (0x80004005): There is already an open DataReader associated with this Connection which must be closed first.
at MySql.Data.MySqlClient.Interceptors.ExceptionInterceptor.Throw(Exception exception)
at MySql.Data.MySqlClient.MySqlCommand.Throw(Exception ex)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()
at MySql.Data.MySqlClient.MySqlTransaction.Rollback()
at MySql.Data.MySqlClient.MySqlTransaction.Dispose(Boolean disposing)
at System.Data.Common.DbTransaction.Dispose()
at Microsoft.EntityFrameworkCore.Storage.RelationalTransaction.Dispose()
at Abp.EntityFrameworkCore.Uow.DbContextEfCoreTransactionStrategy.Dispose(IIocResolver iocResolver) in D:\Github\aspnetboilerplate\src\Abp.EntityFrameworkCore\EntityFrameworkCore\Uow\DbContextEfCoreTransactionStrategy.cs:line 84
at Abp.EntityFrameworkCore.Uow.EfCoreUnitOfWork.DisposeUow() in D:\Github\aspnetboilerplate\src\Abp.EntityFrameworkCore\EntityFrameworkCore\Uow\EfCoreUnitOfWork.cs:line 143
at Abp.Domain.Uow.UnitOfWorkBase.Dispose() in D:\Github\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkBase.cs:line 296
at Abp.AspNetCore.Mvc.Uow.AbpUowActionFilter.d__4.MoveNext() in D:\Github\aspnetboilerplate\src\Abp.AspNetCore\AspNetCore\Mvc\Uow\AbpUowActionFilter.cs:line 49
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
Describe the bug 该问题是怎么引起的?
1、有一个游客外部查看信息接口,现要记录访问次数,我就在原有的查询后添加保存数据。
To Reproduce 重现步骤
2、原来的代码,无错误:
我改动后的代码:
报错信息
There is already an open DataReader associated with this Connection which must be closed first.
具体如下:
INFO 2019-08-29 10:48:49,128 [12 ] ore.Mvc.Internal.ControllerActionInvoker - Executing action method Sg.SFA.Common.CommonInfoAppService.GetInformation (Sg.SFA.Application) with arguments (SooZuohyIxCVEW6MuDRwRg==) - ModelState is Valid
ERROR 2019-08-29 10:48:49,643 [23 ] Mvc.ExceptionHandling.AbpExceptionFilter - There is already an open DataReader associated with this Connection which must be closed first.
MySql.Data.MySqlClient.MySqlException (0x80004005): There is already an open DataReader associated with this Connection which must be closed first.
at MySql.Data.MySqlClient.Interceptors.ExceptionInterceptor.Throw(Exception exception)
at MySql.Data.MySqlClient.MySqlCommand.Throw(Exception ex)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()
at MySql.Data.MySqlClient.MySqlTransaction.Rollback()
at MySql.Data.MySqlClient.MySqlTransaction.Dispose(Boolean disposing)
at System.Data.Common.DbTransaction.Dispose()
at Microsoft.EntityFrameworkCore.Storage.RelationalTransaction.Dispose()
at Abp.EntityFrameworkCore.Uow.DbContextEfCoreTransactionStrategy.Dispose(IIocResolver iocResolver) in D:\Github\aspnetboilerplate\src\Abp.EntityFrameworkCore\EntityFrameworkCore\Uow\DbContextEfCoreTransactionStrategy.cs:line 84
at Abp.EntityFrameworkCore.Uow.EfCoreUnitOfWork.DisposeUow() in D:\Github\aspnetboilerplate\src\Abp.EntityFrameworkCore\EntityFrameworkCore\Uow\EfCoreUnitOfWork.cs:line 143
at Abp.Domain.Uow.UnitOfWorkBase.Dispose() in D:\Github\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkBase.cs:line 296
at Abp.AspNetCore.Mvc.Uow.AbpUowActionFilter.d__4.MoveNext() in D:\Github\aspnetboilerplate\src\Abp.AspNetCore\AspNetCore\Mvc\Uow\AbpUowActionFilter.cs:line 49
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
目前情况:
调用我改动过的接口就一直报这个错误,代码撤销了也报这个错误,连带这张表的其他get接口也报这个错误,别人电脑没调用我的接口还是好好的使用。目前就是我的电脑涉及这张表的这类就看就报这个错误。
The text was updated successfully, but these errors were encountered: