SQL Compact Edition 3.5 SP 1-LockTimeOutException-如何调试?

时间:2020-03-06 14:21:19  来源:igfitidea点击:

在我们的应用程序中,我们间歇性地遇到从SQL CE抛出的LockTimeoutExceptions。我们最近已升级到3.5 SP 1,其中许多似乎已经消失,但偶尔还是会看到它们。我敢肯定这是我们代码中的错误(多线程),但我无法精确地将其固定下来。有没有人有调试此问题的好技术?异常日志是这样的(这些异常从来没有堆栈跟踪):

SQL Server Compact timed out waiting for a lock. The default lock time is 2000ms for devices and 5000ms for desktops. The default lock timeout can be increased in the connection string using the ssce: default lock timeout property. [ Session id = 6,Thread id = 7856,Process id = 10116,Table name = Product,Conflict type = s lock (x blocks),Resource = DDL ]

我们的数据库是读取密集型的,但很少写入,我想我已经在需要保护的所有地方进行了保护。

编辑:SQL CE已经自动使用NOLOCK http://msdn.microsoft.com/en-us/library/ms172398(sql.90).aspx

解决方案

我刚刚意识到3.5 SP1包含了新信息,但让我无法确定。

SQL Server Compact timed out waiting for a lock. The default lock time is 2000ms for devices and 5000ms for desktops. The default lock timeout can be increased in the connection string using the ssce: default lock timeout property. [ Session id = 6,Thread id = 7856,Process id = 10116,Table name = Product,Conflict type = s lock (x blocks),Resource = DDL ]

当尝试删除必须与之建立开放连接的现有表时,我能够识别出它正在发生。

万一其他人遇到此页面,我发现了发生这种情况的另一个原因。我创建了一个SqlCeTransaction来包装各种语句,但我不小心没有在其中一个语句上使用该事务。这是导致我的Lock timeout消息的原因。