Here I am working with Linq to sql I have more then 30000 row in my table.
I used following query for fetching record from database :
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();
}
Some time my query run successfully or some time I got Error : Transaction (Process ID 56) was deadlocked on lock | communication buffer resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
Thanks in advance...
The only way to resolve a SQL Server deadlock is to terminate one of the processes and free up the locked resource so the process can complete. This occurs automatically when SQL Server detects a deadlock and kills off one of the competing processes (i.e., the victim).
A deadlock happens when two (or more) transactions block each other by holding locks on resources that each of the transactions also need. For example: Transaction 1 holds a lock on Table A. Transaction 2 holds a lock on Table B.
Useful ways to avoid and minimize SQL Server deadlocksTry to keep transactions short; this will avoid holding locks in a transaction for a long period of time. Access objects in a similar logical manner in multiple transactions. Create a covering index to reduce the possibility of a deadlock.
Looks like you have general deadlock locking issue with simultaneous table/clustindex scan and update/delete
Look at your resulting query and at its paln - if it have such a scan - try to avoid it with proper indexing or hack it to use (NOLOCK) hint. But nolock hint is not good if you need exact and consistent data without possible phantom rows
And - first of all look at deadlock graph!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With