c# - 事务(进程 ID 56)在锁定时陷入僵局?

标签 c# asp.net sql-server linq-to-sql

我在这里使用 Linq to sql 我的表中有超过 30000 行

我使用以下查询从数据库中获取记录:

IEnumerable<DealsDetails> DD = (from D in DealDbContext1.Deals
                                            where D.Address == City && (D.DealTime >= DateTime.Now || D.DealTime == dealcheck) && PriceMax >= D.DealPrice && D.DealPrice >= PriceMin && DisCountMax >= D.SavingsRate && D.SavingsRate >= DiscountMin && (D.DealTime >= DateTime.Now.AddDays(TimeMin) && D.DealTime <= DateTime.Now.AddDays(TimeMax) || D.DealTime == dealcheck)
                                            select new DealsDetails(
                                                lst,
                                                D.DealId,
                                                D.DealHeadline,
                                                D.DealCategory,
                                                D.BuyPrice,
                                                D.DealPrice,
                                                D.SavingsRate,
                                                D.SavingAmount,
                                                D.RelatedWebsite,
                                                D.Address,
                                                string.Empty,
                                                D.DealImage,
                                                string.Empty,
                                                string.Empty,
                                                D.Time, D.CurrentTime, D.DealTime,
                                               D.Location, string.Empty, string.Empty, D.Latitude, D.Longitude, D.Islocal, D.VendorMail, D.MerchantInfo, D.Review, D.HowItWork, D.DealUrl
                                                ));



if (lstSite.Count > 0 && lstSite[0] != "AllDeals")
                {
                    DD = DD.Where(D => D.RelatedWebsite.Split(',').Where(x => lstSite.Contains(x)).Any()); //.Where(row => row.Category.ToList().Where(x => lst.Contains(x)).Any()).ToList();
            }

有时我的查询成功运行或有时我得到错误:事务(进程ID 56)在锁定时陷入僵局|与另一个进程的通信缓冲区资源,并已被选为死锁牺牲品。重新运行交易。

提前致谢...

最佳答案

看起来您在同步表/clustindex 扫描和更新/删除时遇到了一般的死锁锁定问题

查看您生成的查询及其 paln - 如果它有这样的扫描 - 尝试通过适当的索引避免它或破解它以使用 (NOLOCK) 提示。 但是如果您需要没有可能的幻象行的精确和一致的数据,nolock 提示就不好

而且 - 首先看看死锁图!

关于c# - 事务(进程 ID 56)在锁定时陷入僵局?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8952895/

相关文章:

c# - 将单个值从存储过程返回到 .Net : OUTPUT parameter or ExecuteScalar? 有什么更好的

c# - 获取对数组内部结构的引用

c# - 如何从 List<string> 中删除相同的项目?

sql-server - 在delphi TadoConnection中隐藏内存中的连接用户密码

c# - 父页面数据控件绑定(bind)之后,用户控件中的下一个事件是什么?

asp.net - 设置默认按钮输入 - 母版页

c# - 使用 asp.net 的 SQL Server View

c# - 从 app.config 获取 WCF 客户端端点 IP

c# - .NET 字符串.替换

c# - 将网页重定向到 asp.net 中的同一选项卡