如何防止SqlServer数据库死锁

1.sql 语句加上with(nolock)

例:select * from tableA with(nolock) where ...

 

2.EntityFramework

//with(nolock) 在EF中的使用方法
using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions() { IsolationLevel = IsolationLevel.ReadUncommitted }))
{
  try
  {

    function();
  }
  finally
  {
    ts.Complete();
  }
}

 

3.加索引

 

posted @ 2018-08-22 10:25  Forekoy  阅读(1410)  评论(0编辑  收藏  举报