简体   繁体   English

处理asp.net C#/ SQL Server应用程序的并发问题

[英]Handling concurrency issues for asp.net C# / SQL Server application

How can I handle concurrency issues for an asp.net 4.5 web application (VS2012 and C#, SQL Server) 如何处理asp.net 4.5 Web应用程序(VS2012和C#,SQL Server)的并发问题

For example: 例如:
My scenario is a user might have a chance that is never able to process a queue item. 我的情况是用户可能永远无法处理队列项目。 See the following: 请参阅以下内容:

  1. User A opens the queue item (a), review it carefully 用户A打开队列项目(a),请仔细检查
  2. User B opens the queue item (a), processes it without reviewing 用户B打开队列项目(a),对其进行处理而无需检查
  3. User A decides to process (a), but it's locked, so jumps to item (b) 用户A决定处理(a),但已被锁定,因此跳至项目(b)
  4. User C opens the queue item (b), processes it immediately 用户C打开队列项目(b),立即对其进行处理
  5. User A decides to process (b), but it's locked again 用户A决定处理(b),但是又被锁定了
  6. the same thing happens forever towards user A 永远对用户A发生同样的事情

That will not be ideal for the user A, even though the percentage of this possibility could be really small 即使这种可能性的百分比可能很小,这对于用户A也不是理想的

I am using transactions at the C# code level as well as at the SQL Server stored procedure level. 我正在C#代码级别以及SQL Server存储过程级别使用事务。 Also I make use of ADO.net to communicate with database 我也利用ADO.net与数据库进行通信

My questions are: 我的问题是:

  • do you think creating transactions will take care of concurrency issues ? 您认为创建交易会解决并发问题吗?
  • I am guessing ADO.net has built in concurrency prevention in place? 我猜ADO.net已经内置了并发预防功能? Am I correct ? 我对么 ?
  • do I need to do anything else to prevent concurrency issues other than creating transactions and using ADO.net? 除了创建事务和使用ADO.net之外,我还需要做其他事情来防止并发问题吗?

In short: You may resolve concurrency issues by using traditional method called timestamp column. 简而言之:您可以使用称为timestamp列的传统方法解决并发问题。

The timestamp column of a table can be used to determine whether any value in the table row has changed since the last time the table was read. 表的时间戳列可用于确定自上次读取表以来,表行中的任何值是否已更改。 This article describes a way to use the timestamp column of a table for optimistic concurrency control in Microsoft SQL Server 2005. 本文介绍了一种使用表的时间戳列进行Microsoft SQL Server 2005中的乐观并发控制的方法。

To get more detailed explanation of this approach, follow this article 要获得有关此方法的更多详细说明,请关注本文。

In addition , you may also look at step-by-step implementation guidelines of Implementing Optimistic Concurrency with SQL Timestamps . 此外 ,您还可以查看使用SQL时间戳实现乐观并发的分步实施指南。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM