如何让应用程序在浏览器中途关闭时回滚?
如果我的网络应用程序的浏览器半关闭,我会尝试停止将数据存储到数据库中。
例如:
单击“提交”按钮后,在此过程中,有人关闭了浏览器窗口或互联网连接断开。我希望应用程序回滚所有已提交的数据。是否可以在应用程序中执行此操作而不更改存储过程中的配置?
I try to stop the data storing to database if the browser is closed half way for my web application.
For example:
After click Submit button, during the process, someone close the browser window or internet connection is down. I want the application to rollback all the committed data. Is that possible to do that in application without changing configuration in the store procedure?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不——如果不创建解决方案的最终破解,这不可能以任何正常方式实现。
通常在这种情况下,数据是分阶段提交的。如果他们从未“完成”下一步,则他们之前的数据将在稍后的某个过程中被删除。
No - this is not possible in any normal way without creating the ultimate hack of a solution.
Normally in a case like this data is committed in stages. If they never 'complete' the next step, their prior data is removed by some process at a later point.
我可以建议一个基于 Response.IsClientConnected 的想法,说明用户是否仍处于连接状态。
我认为插入数据的sql命令太快以至于你永远无法捕捉到它,但是如果sql命令不是那么快你可以尝试一下,尽管我建议找到一种不同的方式来应用sql 事务需要很长时间。此外,如果用户停止与页面的连接,也会引发异常。
I can suggest an idea base on
Response.IsClientConnected
that say you if the user is still connected.I think that the sql command to insert data is too fast that you never catch it, how ever if sql command is not so fast you can try it, even tho I suggest to find a different way to apply long time takes sql transactions. Also if the user stops the connection to the page an exceptions also thrown.
我很好奇您如何执行数据访问。如果您使用 .NET,我会对 System.Transactions.TransactionScope() 进行一些研究。正如前面提到的,这是 sql 中事务的替代方案,并且仅依赖于您的数据访问层实现(例如实体框架或 Linq to SQL 与存储过程或普通 T-SQL)
http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx
除了这个建议之外,作为开发人员,您还可以控制边缘情况,例如这些。例如,如果用户处于多步骤过程的中途;业务规则和用例在这里定义了您如何处理此类场景。实现事务状态可能是一种选择,其中一些人会忽略废料数据,另一些人会保存它以防万一用户返回。鉴于此,我想说这可能是一个设计问题而不是开发问题。
我希望这有帮助。干杯!
I'm curious how you are performing your data access. If you are using .NET I'd do some research on System.Transactions.TransactionScope(). This is an alternative to transactions, as mention previously, in sql and is only dependent upon your data access layer implementation (e.g. Entity Framework or Linq to SQL vs. Stored Procedures or plain T-SQL)
http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx
Beyond this suggestion, it's up to you as the developer to control edge cases such as these. For example if the user is mid-way in a multi-step process; it is here the business rules and use cases define how you are to handle such scenarios. Implementing transactional state might be an option where some dismiss the scrap data others save it just in case the user returns. Given this, I'd say this is potentially a design issue rather than a development issue.
I hope this helps. Cheers!