并发事务调用导致 .net Web 服务中出现重复响应

发布于 2024-11-28 21:17:05 字数 257 浏览 0 评论 0原文

大家好,我有一个关于来自 3.5 框架编写的 .net Web 服务的并发存储过程调用的问题。

我正在构建一个由许多用户使用的 Web 服务,需要从 oracle 数据库返回联系信息。 问题是,当超过 1 个用户同时点击时,数据库会返回相同的联系信息。我已经在SP中编写了状态更新查询。仅当状态更新发生之前有 2 个或更多请求读取同一记录时,我才会遇到此问题。我已经使用了事务和事务范围,但它不能解决问题。谁能告诉我我是否正确解决了这个问题,或者我应该寻找其他方式。非常感谢任何帮助。

Hi all I have a question on concurrent stored procedure calls from a .net web service written in 3.5 framework.

I am building a web service that is used by many users and needs to return contact information from oracle database.
The issue is when more than 1 user clicks at the same time the db returns the same contact info. I have written the status update query in the SP. I am having this issue only when 2 or more requests read the same record before the status update happens. I have used transaction and transaction-scope but it doesn't solve the issue. Can anyone tell me if i am tackling the problem right or should i be looking at some other way. Any help is greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小姐丶请自重 2024-12-05 21:17:06

您对数据库的“读取”操作并不是真正的读取,因为它更新了相关记录。听起来您需要的是在第二个读取和更新操作开始之前完成并提交第一个读取和更新操作。

我不是数据库/Oracle 专家,所以如果这个答案有些模糊,我深表歉意:有没有办法在读取和更新操作开始时锁定有问题的表 - 也许是 Oracle 事务设置?如果是这样,那应该可以实现您正在寻找的内容。

请注意,您本质上是对该表的单线程访问,这可能会对性能产生影响,具体取决于并发用户的数量以及访问表的频率。您可能需要考虑实现要求的其他方法。

Your "read" operation on the database isn't really a read, since it updates the record in question. Sounds like what you need is for the first read-and-update operation to complete and commit before the second read-and-update operation begins.

I'm not a database/oracle guru, so I apologize if this answer is somewhat vague: is there a way to lock the table in question at the start of the read-and-update operation - perhaps an oracle transaction setting? If so, that should accomplish what you're looking for.

Note that you're essentially single-threading access to that table, which could potentially have performance implications, depending on the number of concurrent users and how often the table is accessed. You might want to consider alternate ways of accomplishing the requirement.

澜川若宁 2024-12-05 21:17:05

听起来您的存储过程代码就是我们在行业中所说的“狡猾”。

一般来说,它应该是一个,

UPDATE table
SET status = 'READ'
WHERE ...
RETURNING col_1, col_2 INTO var1, var2;
RETURN;

它可能正在执行一个 SELECT,然后根据 ID 进行 UPDATE,而不检查状态是否已被另一个事务更改

Sounds like your stored procedure code is what we term in the trade 'dodgy'.

Generally it should be an

UPDATE table
SET status = 'READ'
WHERE ...
RETURNING col_1, col_2 INTO var1, var2;
RETURN;

It is probably doing a SELECT then an UPDATE based on ID without checking to see whether the status has been changed by another transaction

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文