如何使 VB.NET 应用程序作为多用户工作?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19436798/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 15:31:29  来源:igfitidea点击:

How to make VB.NET application work as Multi-user?

vb.netms-access-2007

提问by Rahul Sharma

I am developing a VB.Net application. That application might be working on a LAN. MS Access as a back end will be used. I have developed many single user applications, but don't know of multi user , LAN, manage DB etc. How do I make the program as Multi user on LAN. Data will be accessed at the same time. How to manage such things. Please give me some help and Guidance.

我正在开发一个 VB.Net 应用程序。该应用程序可能正在 LAN 上运行。将使用 MS Access 作为后端。我开发了许多单用户应用程序,但不知道多用户、局域网、管理数据库等。如何在局域网上将程序设为多用户。数据将同时被访问。如何管理这样的事情。请给我一些帮助和指导。

Thanks

谢谢

回答by Steve

Your VB application does not care how many people run it.

您的 VB 应用程序并不关心有多少人运行它。

Your database, with MS Access, has some serious issues with multiple users. Get away from it if you can. SQL Server has a free version called SQL Express. If you only plan on 2 people, you might be OK with Access for a while but be prepared to support it more.

您的带有 MS Access 的数据库存在多个用户的严重问题。如果可以,请远离它。SQL Server 有一个免费版本,称为 SQL Express。如果您只计划 2 人,您可能会暂时接受 Access,但要准备好提供更多支持。

That was all the easy stuff, now you have to think about how you are going to handle multiple users trying to access and update the same data (concurrency).

这是所有简单的事情,现在您必须考虑如何处理尝试访问和更新相同数据(并发)的多个用户。

Imagine this, you are a user looking at employee record 1 and so is someone else. You change the birthday and save. The the other user changes thier suppervisor and saves. How do you know something changed? What do you do if something changed? These are questions I cannot answer for you, you must decide based on your situation.

想象一下,您是查看员工记录 1 的用户,其他人也是。您更改生日并保存。另一个用户更改他们的主管并保存。你怎么知道有什么变化?如果事情发生了变化,你会怎么做?这些问题我无法为您解答,您必须根据自己的情况来决定。

There are 2 main types of concurrency, optimistic and pessimistic. See this link for a great explaination and discussion on them: optimistic-vs-pessimistic-locking

并发有两种主要类型,乐观和悲观。有关它们的详细解释和讨论,请参阅此链接:乐观与悲观锁定

You can look at this on a table-by-table basis.

您可以逐个表地查看此内容。

  1. If a table is never updated, you dont have to worry about concurrency
  2. If a table is rarely updated, like a table of states, you can decide if it is worth the extra effort to add concurrency.
  3. Everything else, pretty much should have some type of concurrency.
  1. 如果一个表永远不会更新,你就不必担心并发
  2. 如果一个表很少更新,比如一个状态表,你可以决定是否值得付出额外的努力来增加并发性。
  3. 其他一切,几乎都应该具有某种类型的并发性。

Now, the million dollar question, how?

现在,百万美元的问题,如何?

You will find as many ways to handle concurrency as you will find colors in the rainbow. Here are some of the ones I like:

您将找到与彩虹中的颜色一样多的处理并发性的方法。以下是我喜欢的一些:

  1. Simple number that you increment with each save. Small and easy.
  2. DateTime stamp - As long as you dont expect to ever have 2 people save the same record during the same second, this is easy. (I personally dont like it by it's self)
  3. User Name - Pretty simple gives a little bit of an audit by knowing who last inserted/edited the record but doesn't handle an issue I have seen to often. Imagine the same senerio as above but you had 2 instances of record 1. Now you change the data again, maybe supervisor, and when you save, you overwrite the changes from your first save with those of the second save.
  4. Guid - VB can create a guid, SQL Server can create a guid and so can Access. It is nice an unique and most important, you can create it on the client so you dont have to requery the database after you save the record to get a refreshed record.
  5. Combination of these. I like 2 and 3 myself. Gives a mini audit and is unique to the user.
  1. 每次保存都会增加的简单数字。小而容易。
  2. 日期时间戳 - 只要您不希望在同一秒内有两个人保存相同的记录,这很容易。(我个人不喜欢它本身)
  3. 用户名 - 非常简单,通过知道谁最后插入/编辑记录但不处理我经常看到的问题,可以进行一些审核。想象一下与上面相同的情况,但您有记录 1 的 2 个实例。现在您再次更改数据,可能是主管,当您保存时,您用第二次保存的更改覆盖第一次保存的更改。
  4. Guid - VB 可以创建 guid,SQL Server 可以创建 guid,Access 也可以。这是一个很好的独特之处,最重要的是,您可以在客户端上创建它,这样您就不必在保存记录后重新查询数据库以获得刷新的记录。
  5. 这些的组合。我自己喜欢2和3。进行小型审核并且对用户而言是唯一的。

If you use a DataAdapter, by default, MS will assume concurrency checking means to compare EVERY field to make sure it did not change. This works, but is completely un-scaleable and should not be done.

如果您使用DataAdapter,默认情况下,MS 将假定并发检查意味着比较每个字段以确保它没有更改。这有效,但完全不可扩展,不应该这样做。

All of this depends on the size of your application and how you see it being used. Definately do some more research before you settle on a decision.

所有这些都取决于您的应用程序的大小以及您如何看待它的使用情况。在做出决定之前,一定要多做一些研究。

回答by JFish222

There are a number of solutions here.

这里有许多解决方案。

If I may suggest a drastic alternative, have you considered pairing the client running on the user's computer with a server component (through a web service)? A simpler alternative would be for the client to talk directly to a SQL Server (or other database) instance through the network?*

如果我可以建议一个激烈的替代方案,您是否考虑过将在用户计算机上运行的客户端与服务器组件(通过 Web 服务)配对?一个更简单的替代方法是让客户端通过网络直接与 SQL Server(或其他数据库)实例对话?*

*I'm not a fan of having client side apps talk directly to the database. It will mean maintenance headaches in the future, but I included it to give you options

*我不喜欢让客户端应用程序直接与数据库对话。这将意味着未来的维护难题,但我将其包含在内是为了给您提供选择

.

.

I found this random examplevia Google so YMMV.

我通过 Google找到了这个随机示例,所以 YMMV。