I have used TransactionScope in the past with desktop client applications to roll back an incomplete multi-step transaction. That approach would seem unlikely to work in an Web application.
我过去曾使用TransactionScope与桌面客户端应用程序回滚不完整的多步骤事务。这种方法似乎不太适用于Web应用程序。
Can anyone suggest ways in which multiple steps, across several pages, can be ensured to roll back if the entire process is not completed? (their browser crashes or they close the browser in mid process for example)
任何人都可以建议如果整个过程没有完成,可以确保多个页面的多个步骤可以回滚的方法吗? (例如,他们的浏览器崩溃或者他们在中间过程中关闭浏览器)
Certainly, i could write to a temp table of some sort, then transfer the final record to the real table in a single transaction, but that runs the risk of race conditions. I'd like to begin a transaction, serve several pages, each page writing a piece of the transaction to the table(s), then completing the transaction with a commit, and if the transaction is not completed, then it is rolled back when the session ends.
当然,我可以写入某种临时表,然后在一次交易中将最终记录转移到真实表中,但这会带来竞争条件的风险。我想开始一个事务,提供几个页面,每个页面将一个事务写入表中,然后用提交完成事务,如果事务没有完成,那么它将在回滚时回滚会议结束。
Or am i not thinking the right way? Suggestions?
或者我没有想到正确的方法?建议?
Since i'm using MVC 3, EF 4.1 and Ninject, i'm not sure how that will affect the solution, but i thought i'd include that information.
由于我使用的是MVC 3,EF 4.1和Ninject,我不确定这将如何影响解决方案,但我认为我会包含这些信息。
2 个解决方案
#1
8
There is no database transaction / TransactionScope
across several pages. Even trying to do something like that is terribly wrong.
跨多个页面没有数据库事务/ TransactionScope。即使尝试做这样的事情也是非常错误的。
You have two options to solve the problem:
您有两种方法可以解决问题:
-
Use
Session
Store your data in session and persist it to the database only if user completes all of the steps, and confirms the save. This is definitely what you need.]
仅在用户完成所有步骤时才将数据存储在会话中并将其保留到数据库中,并确认保存。这绝对是你需要的。]
-
Use workflow foundation and long running transactions.
使用工作流基础和长期运行的事务。
Long running transactions are not database transactions - they are a completely custom solution where you must implement compensation (rollback of long running transactions) manually. You still have to detect somehow that your workflow should be compensated, but this is not necessary for your solution. It is for a solution where you need a "transaction" for multiple sessions.
长时间运行的事务不是数据库事务 - 它们是一个完全自定义的解决方案,您必须手动实现补偿(长时间运行的事务回滚)。您仍然必须以某种方式检测您的工作流程应该得到补偿,但这对您的解决方案来说不是必需的。它适用于需要多个会话的“事务”的解决方案。
#2
1
You might look at setting up nservicebus or masstransit and use their saga facilies.
您可能会考虑设置nservicebus或masstransit并使用他们的saga facilies。
#1
8
There is no database transaction / TransactionScope
across several pages. Even trying to do something like that is terribly wrong.
跨多个页面没有数据库事务/ TransactionScope。即使尝试做这样的事情也是非常错误的。
You have two options to solve the problem:
您有两种方法可以解决问题:
-
Use
Session
Store your data in session and persist it to the database only if user completes all of the steps, and confirms the save. This is definitely what you need.]
仅在用户完成所有步骤时才将数据存储在会话中并将其保留到数据库中,并确认保存。这绝对是你需要的。]
-
Use workflow foundation and long running transactions.
使用工作流基础和长期运行的事务。
Long running transactions are not database transactions - they are a completely custom solution where you must implement compensation (rollback of long running transactions) manually. You still have to detect somehow that your workflow should be compensated, but this is not necessary for your solution. It is for a solution where you need a "transaction" for multiple sessions.
长时间运行的事务不是数据库事务 - 它们是一个完全自定义的解决方案,您必须手动实现补偿(长时间运行的事务回滚)。您仍然必须以某种方式检测您的工作流程应该得到补偿,但这对您的解决方案来说不是必需的。它适用于需要多个会话的“事务”的解决方案。
#2
1
You might look at setting up nservicebus or masstransit and use their saga facilies.
您可能会考虑设置nservicebus或masstransit并使用他们的saga facilies。