NHibernate和自动递增ID死锁

时间:2012-10-18 19:12:49

标签: nhibernate

我一直在使用SharpArchitecture和NHibernate来构建我的网站,这可能有很多用户。我的表在数据库设置中使用主键设置为IDENTITY(1,1)。最近几天我一直注意到基于日志文件发生的一堆死锁问题:

System.Data.SqlClient.SqlException: Transaction (Process ID 55) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.

我有时会得到这个可能有关的错误:

System.Data.SqlClient.SqlException: Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.

在我的web.config中,我已经包含了这一行来设置db隔离属性:

<property name="connection.isolation">ReadUncommitted</property>

基于我通过搜索找到的内容,即使我有ReadUncommitted,自动递增的ID也会锁定表。话虽如此:

  • 我的结论是否正确?
  • 如果是这样,我假设如果我使用像HiLo或GuidComb之类的东西生成ID,它会解决问题吗?

谢谢!

1 个答案:

答案 0 :(得分:1)

  • 可能是的

对于许多用户而言,HiLo还可以减少数据库的流量和负载,因此无论如何切换到它都会很好。

相关问题