Subsonic:在视图上选择,锁定表更新?
我现在有一个正在运行的网站。我正在使用 Subsonic 来处理数据库连接等。 我在更新表时遇到超时过期错误(例如员工)。当我检查 sp_who2 时,我看到 PID 的挂起连接正在通过另一个 pid 进行更新,因此我运行探查器并发现每当发生此挂起连接时,被阻止的 pid 是视图上的 select 语句(例如ActiveEmployees,与表相同,但带有一些 where 条件)。
任何人都知道为什么视图上的 Select 语句可能会导致更新失败。如果是其他的(比如 select 由于更新而失败)可能是合理的。 有什么方法可以让我在不锁定表的情况下对视图进行选择?
PS:我使用的是Sql server 2005和subsonic 2.2。
I have a Web site live and running now. I am using the Subsonic to handle the database connections etc.
I am getting time out expired error while updating a table (say Employee). When I check sp_who2, I see the suspended connection for the PID which is updating with a block by anothor pid, so I run the profiler and found out when ever this suspended connection occur, the blocked pid is a select statement on the view (say ActiveEmployees, which is the same as the table but with some where conditions).
Anyone know why a Select statement on the view could cause failure in update. If it is other (like select fails due to update) may be reasonable.
Is there any way for me to make select on a view without locking the table?
PS: I am using the Sql server 2005 and subsonic 2.2.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您不关心返回数据的准确性(它可能会返回未提交的行),您可以向视图中的 select 语句添加 with(nolock) 提示。
当 select 语句扫描其他线程插入的表时,我们也会遇到超时。我通过添加我们的选择使用的适当索引解决了这个问题。
You might add with(nolock) hint to the select statement in the view if you don't care about accuracy of the returned data (it will return uncommited rows possibly).
We encountered timeouts also when the select statements where scanning a table that other thread was inserting into. I resolved the issue by adding appropriate index that is used by our select.