我的程序有问题,通过解决这个问题,也许可以通过使用单例方法来完成。但是,我从一些文章中读到,他们说,这不是实现它的好方法,因为 asp.net 应用程序并发用户可能有很多。
我的问题是,系统运行号是基于数据库示例中的特定记录:
- document_type="INV",document_year=2015,document_month=04,document_running=0102。
- document_type="INV",document_year=2015,document_month=05,document_running=0002。
因此,当用户新建一条记录时,获取新流水号的逻辑如下:
- 获取文档类型 = "inv" ,当年当月,
- 如果没有找到。新建单据类型,年月记录,流水号为0001。
- 如果找到。跑步+1。
现在,问题出来了。我的情况是 5 个用户在按下“保存”按钮创建新记录时收到了记录信息: - document_type="INV" , document_year=2015 , document_month=05, document_running=0002。
并且 5 个用户获得相同的运行号 INV15-05-0003(在 0002 + 1 之后)。正确的应该是INV15-05-0003、INV15-05-0004、INV15-05-0005、INV15-05-0006和INV15-05-0007。
如果所有用户都收到错误/过时的信息,我们应该如何避免。希望你们都能理解我蹩脚的英语。问候, MH