2

我正在使用 linq to sql 并运行直接 SQL 查询 - select 语句 - 它使用 (XQuery) 查询 XML 列。多个这样的查询并行运行,我遇到了死锁异常。

select 在运行时是否会获得某种锁?也有与 Serializable 隔离级别并行发生的更新。

如何解决此问题的任何指示都可能会有所帮助。如何在 Linq To SQL 中指定 NOLOCK?

4

2 回答 2

3

Why are you getting a deadlock? SELECT on its own cannot deadlock with another SELECT. There must be more happening. Capture the deadlock XML graph and post it here so we can help you analyze it. Once we have the deadlock understanding we can recommend a solution, which is almost always a required index which you're missing.

Do NOT enable dirty reads (NOLOCK hints or read uncommitted isolation level), that is not the right approach. Dirty reads are inconsistent reads and return incorrect data. If needed, row versioning-based reads may be required, that's how this very site once solved it's issues.

于 2012-10-04T06:16:44.580 回答
3

我在Scott Hanselman 的博客文章中查看了它。像这样尝试的示例

ProductsNewViewData viewData = new ProductsNewViewData();
using (var t = new TransactionScope(TransactionScopeOption.Required,
new TransactionOptions { 
    IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted 
}))
{
  viewData.Suppliers = northwind.Suppliers.ToList();
  viewData.Categories = northwind.Categories.ToList();
}

希望它对你有帮助。在他的博客文章中阅读更多内容。

于 2012-10-04T05:00:26.523 回答