且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

防止并发访问sql服务器数据库

更新时间:2022-06-13 09:09:01

由于某种原因而不能使用事务,我建议在表的每一行中添加一个上次修改的"时间戳字段.当您生成要发送给用户的asp页时,请将最后修改的时间戳记添加为隐藏字段.如果用户在页面上提交任何表单,则可以使用此字段针对数据库的当前状态进行测试.如果时间戳匹配,则没有并发访问发生.否则,报告问题.
If you can''t use transactions for some reason, I would suggest adding a "last modified" timestamp field to each row of the table. When you generate the asp page to send to the user, add the last modified timestamp as a hidden field. If the user submits any form on the page, you can use this field to test against the current state of the database. If the timestamps match, then no concurrent access has occurred. Otherwise, report the problem.


谢谢您的提问.


您可以通过阅读以下图标来​​解决此问题:

使用SqlDataSource实现乐观并发
http://www.asp.net/data-access/教程/与sqldatasource-cs一起实现优化并发

对于ADO.NET,请参见:

ADO.NET中的并发控制
http://msdn.microsoft.com/en-us/library/22hhd212.aspx


谢谢,
马蒙
Thank you for your question.


You can solve this problem by reading the following likns:

Implementing Optimistic Concurrency with the SqlDataSource
http://www.asp.net/data-access/tutorials/implementing-optimistic-concurrency-with-the-sqldatasource-cs

For ADO.NET, please see:

Concurrency Control in ADO.NET
http://msdn.microsoft.com/en-us/library/22hhd212.aspx


Thanks,
Mamun