SQL Server Compact 等待锁超时

发布于 2024-08-04 20:48:42 字数 661 浏览 2 评论 0原文

我有一个应用程序,我将 Sql Compact 3.5 与 VS2008 一起使用。我在应用程序中运行多个线程来联系紧凑数据库并访问行。它以某种方式选择并删除这些行,即选择并向应用程序提供 5 行,然后从表中删除这些行。它在单线程中工作得很好,但如果我使用多个线程,即如果有 3 个或更多线程正在运行,我经常会收到超时错误!我增加了连接字符串中的超时属性,但它没有给我预期的结果。错误日志如下:

SQL Server Compact 等待锁超时。设备的默认锁定时间为 2000 毫秒,台式机的默认锁定时间为 5000 毫秒。可以使用 ssce:default lock timeout 属性在连接字符串中增加默认锁定超时。 [会话id = 5,线程id = 4204,进程id = 4808,表名称= XXX,冲突类型= x锁(s块),资源= TAB]

我用来检索的查询如下:

“ select Top(5) * from TableName order by id; 从 TableName where id in 中删除(从 TableName order by id 中选择 top(5) id); “

有什么办法可以避免这个超时异常吗???????

上面的查询我在VS2008中作为一个事务,一个使用SQLCECommand,另一个使用SqlCEDataAdapter。

任何想法!!!!!!! 回复

I'm having an application in that i use Sql Compact 3.5 with VS2008. I'm running multiple threads in my application which contacts the compact database and accesses the row. It selects and deletes those rows in a fashion i.e selecting and giving to the application 5 rows and deleting those rows from the table. It works great with a single thread but if i use multiple threads i.e if 3 or more threads are running I get very often the TimeOut Error!!! I have increased the Time out property in the connection string but it didn't give me expected result. The error log is as follow:

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 = 5,Thread id = 4204,Process id = 4808,Table name = XXX,Conflict type = x lock (s blocks),Resource = TAB ]

The Query that I use to retrieve is as follows:

"
select Top(5) * from TableName order by id;
delete from TableName where id in(select top(5) id from TableName order by id);
"

Is there any way by which we can avoid this Time Out exception???????

The above query I un as a transaction in VS2008 one using SQLCECommand and the other using SqlCEDataAdapter.

Any Idea!!!!!!
Reply

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

逐鹿 2024-08-11 20:48:42

我也遇到过同样的问题。我知道这是一个老问题,但对于任何在谷歌上搜索答案的人来说,当我完成它时,我通过在我的 dataReader 上调用 Reader.Close() 来修复它。

该应用程序是单线程的,但如果我太快发出太多请求,我就会一直收到此消息。

我希望这有帮助!

I've had exactly the same problem. I know this is an old question but for anyone Googling for an answer I fixed it by calling Reader.Close() on my dataReader when I'd finished with it.

The application was single threaded but I was getting this all the time if I made too many requests too quickly.

I hope that helps!

嘦怹 2024-08-11 20:48:42

您可以尝试一些连接字符串设置,例如“默认锁定超时”等。

请参阅 SqlCeConnection.ConnectionString 属性位于 http://msdn.microsoft.com/en-us/library/system.data.sqlserverce.sqlceconnection.connectionstring(VS.80).aspx

(除了用分号链接查询时遇到问题之外,我什么也没遇到。)

There are some connection string settings you can try, like "default lock timeout", and so on.

See SqlCeConnection.ConnectionString Property at http://msdn.microsoft.com/en-us/library/system.data.sqlserverce.sqlceconnection.connectionstring(VS.80).aspx.

(I had nothing but trouble chaining queries with the semi-colon.)

只是我以为 2024-08-11 20:48:42

我刚才遇到了同样的问题...

问题是我在事务中完成了 ALTER 表,然后尝试稍后在同一事务中从该表中读取数据。哎呀。从事务中删除了 ALTER 表,一切又恢复正常了。

I had the same problem just now...

The issue was that I had done an ALTER table in a transaction and then tried to read from that table later in the same transaction. oops. Removed the ALTER table from the transaction and everything is wonderful again.

此刻的回忆 2024-08-11 20:48:42

尽管 SQLCE 的多线程是可能的,但数据库对并发事务的限制非常有限。

在 using 语句中封装每个实现 IDisposable 的 SQLCE 相关类绝对是一个好主意,但根据负载的不同,锁定错误仍然可能发生。

连接字符串超时选项似乎都不能解决这个问题。
作为解决方法,我只是在发生锁定错误时重试该操作。

请注意,大型 SQL 服务器不会受到此影响。并行处理工作没有任何问题。

Although multi threading with SQLCE is possible the database is very limited to concurrent transactions.

Encapsulating every SQLCE related class that implements IDisposable in using statements is definitly a good idea but lock error might still occur depending on load.

None of the connection string timeout options seem to solve that.
As a workaround I just retry the operation in case of a lock error.

Note that the big SQL server does not suffer on this. Parallel processing works without any issues.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文