2012-01-21 176 views
6

在这里我正在与Linq到SQL我有更多然后30000行在我的表中。交易(进程ID 56)锁定时死锁?

我用下面的查询从数据库中获取记录:

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)被死锁的锁|通信缓冲区资源与另一个进程并被选为死锁受害者。重新运行交易。

在此先感谢...

+0

在SQL Server的错误日志中会出现死锁条目,你可以发布吗?如果没有,请打开[traceflag 1204或1222](http://msdn.microsoft.com/zh-cn/library/ms178104.aspx) – Andomar

+0

查询需要多长时间才能运行? – RobJohnson

+1

什么版本的SQL Server? [如果2008年查看是否可以从默认的扩展事件会话中获取死锁图表](http://dba.stackexchange.com/questions/10644/deadlock-error-isnt-returning-the-deadlock-sql/10646#10646 )。否则,设置下次捕获。 –

回答

2

看起来你有一般的僵局锁定问题与同时表/ clustindex扫描,并在您生成的查询,并在其PALN更新/删除

看 - 如果有这样的扫描 - 尝试通过适当的索引避免它或破解它(NOLOCK)提示。 NOLOCK提示是不是好,如果你需要在没有可能的幻像行

精确,一致的数据 - 首先看看死锁图形的!