防止并发访问sql服务器数据库 [英] prevent concurrent access to sql sever database

查看:129
本文介绍了防止并发访问sql服务器数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个asp .net页面,其中显示了一个内嵌复选框列的gridview. asp .net页面包含两个带有文本成功",失败"的按钮.
问题是,列出所有已通过考试的学生的gridview可以由两个管理员访问,例如,他们将选中同一行的复选框,然后单击成功",而另一个单击失败".这样我就可以在数据库中进行并发访问了.因此,有什么方法可以防止数据库中出现这种情况.
请注意,该网页还包含其他两个gridview,第一个列出了成功通过考试的学生,第二个列出了未通过考试的学生.

I have an asp .net page which shows a gridview that embed a checkbox column. the asp .net page include a two buttons with text "succed" "fail".
The problem is that the gridview which lists all students that have passed an exam can be accessed by two managers who will for example check the check box of the same row and one click "succed" and the other "fail". so i ll have a concurrent access in the database. so is there any way to prevent that in the database.
Note that the web page includes also two other gridview one first one lists the students who succeded in the exam and the second one lists the student which fails.

推荐答案

由于某种原因而不能使用事务,我建议在表的每一行中添加一个上次修改的"时间戳字段.当您生成要发送给用户的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


这篇关于防止并发访问sql服务器数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆