C#数据库应用程序并发 [英] C# Database Application Concurrency

查看:122
本文介绍了C#数据库应用程序并发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用SQL Server 2005 express作为后端在c#中编写了一个多用户应用程序。

I wrote a multi user app in c# some time age using SQL Server 2005 express as back-end.

我有一个订单集合。为了使用这个类,你需要实例化它,只需调用Load(CustomerCode)方法为了用指定的客户的订单填充集合。

I have a Orders collection. In order to use this class you would need to instantiate it and just call the Load(CustomerCode) method in order to populate the collection with the specified customers`s orders.

我的问题:

如何强制实施并发,以便只有1个用户可以为特定客户请求订单集合?当用户完成对象(当对象设置为null时),
我需要使它再次可用。

How do I enforce concurrency, so that only 1 user can request a Orders collection for a specific customer? When the user is done with the object(when the object is set to null), I will need to make it available again.

推荐答案

您需要实施悲观离线锁定模式。

基本上你有一个表,你把记录表示在其他表记录上的锁。当您想要编辑记录时,首先检查锁定表中是否有锁定,然后在您的域逻辑/ UI中做出相应的反应。

Essentially you have a table that you put records in that represent a "lock" on records in other tables. When you want to edit a record, you check to see if there's a lock in the lock table first, and react accordingly in your domain logic/UI.

必须是数据库,它可以是内存中的缓存。当我在我的例子中说table时,我的意思是一个逻辑表,不一定是数据库。

It doesn't have to be a database, it could be an in-memory cache. When I say "table" in my example, I mean a logical table, not necessarily a database one.


$ b冲突,通过避免它们。
它强制业务事务到
获取对一块数据
的锁,然后开始使用它,所以大多数时候
,一旦你开始
业务事务你可以漂亮
确保你将完成它,而不是
被并发控制退回。

Pessimistic Offline Lock prevents conflicts by avoiding them altogether. It forces a business transaction to acquire a lock on a piece of data before it starts to use it, so that, most of the time, once you begin a business transaction you can be pretty sure you'll complete it without being bounced by concurrency control.

这篇关于C#数据库应用程序并发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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