0

“执行超时。在操作完成之前超时时间已过或服务器没有响应。” 在分布式 sql server 缓存中

我调用控制器的方法

 public async Task<IEnumerable<NormalDeposit_DepositDetails>> GetAllNormalDeposit_DepositDetails_Async()
    {
        if (IsCacheEnable == true)
        {
            IEnumerable<NormalDeposit_DepositDetails> NormalDeposit_DepositDetails_AllList;
            var KeyHere = KeyCache.GenCacheKey(CacheKeyList.NormalDeposit_DepositDetails_CacheSecurityKeyString, SecurityKey);
            var GetCachehere = await distributedCache.GetStringAsync(KeyHere);
            if (string.IsNullOrEmpty(GetCachehere))
            {
                context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
                NormalDeposit_DepositDetails_AllList = await context.NormalDeposit_DepositDetails.AsNoTracking().ToListAsync();


                DistributedCacheEntryOptions options = new DistributedCacheEntryOptions();
                options.AbsoluteExpiration = DateTime.Now.AddHours(12);
                options.SlidingExpiration = TimeSpan.FromMinutes(30);
                var Value = JsonConvert.SerializeObject(NormalDeposit_DepositDetails_AllList);
               await distributedCache.SetStringAsync(KeyHere, Value, options);
                return NormalDeposit_DepositDetails_AllList;
            }
            else
            {
                return JsonConvert.DeserializeObject<IEnumerable<NormalDeposit_DepositDetails>>(GetCachehere);
            }
        }
        else
        {
            IEnumerable<NormalDeposit_DepositDetails> NormalDeposit_DepositDetails_AllList;
            context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
            NormalDeposit_DepositDetails_AllList = await context.NormalDeposit_DepositDetails.AsNoTracking().ToListAsync();
            return NormalDeposit_DepositDetails_AllList;
        }
    }

我的控制器方法

    [AllowAnonymous]
    [HttpPost]
    public async Task<IActionResult> GetDataHere()
    {
        var ItemsHere = await normalDeposit_DepositDetailsInterface.GetAllNormalDeposit_DepositDetails_Async();
        decimal NormalDeposit_Deposit_AfterDeposit = ItemsHere.Where(a => a.Status == true ).Sum(s => s.Amount);

        return View("Index");
    }

App.json 方法

  "ConnectionStrings": {
    "ConnectionVar": "Server=DESKTOP-IACJQY;Database=$aZ1*,z.ahbz.@!78z)c;User Id=*&zkaUI190%$User{]z!Z,a;password=+1z)9.,!aEL%ZKI9@$MnaL><f;Trusted_Connection=False;MultipleActiveResultSets=true;Connection Timeout=1800;"
  }

启动.cs

        services.AddDistributedSqlServerCache(options =>
        {
            options.ConnectionString = _config.GetConnectionString("ConnectionVar");
            options.SchemaName = "dbo";
            options.TableName = "SQLSessions";
            options.DefaultSlidingExpiration = TimeSpan.FromMinutes(30);
            options.ExpiredItemsDeletionInterval = TimeSpan.FromMinutes(30);
        });

我的问题:-

  • {"Execution Timeout Expired. 在操作完成之前超时时间已过或服务器没有响应。"} 在分布式 sql server 缓存中

当调试命中时await DistributedCache.SetStringAsync(KeyHere, Value, options); . 记录超过 3000 行。

如果我遗漏了什么,请帮忙。或者需要在代码中添加。在此先感谢您的支持和关心。

4

0 回答 0