跨多个HTTP请求的单个数据库事务 [英] Single Database Transaction Across A Multiple HTTP Requests

查看:376
本文介绍了跨多个HTTP请求的单个数据库事务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须将大量数据保存到数据库.由于数据太大而无法在单个请求中发送,因此我正在反复从客户端进行AJAX调用以将数据发送到服务器.但是我想在单个事务中将数据保存到数据库.如果保存了所有数据,则仅提交否则进行回滚.是否可以在多个AJAX HTTP请求中的单个事务中保存所有数据?

I have to save large amount of data to database. From client I am making repeated AJAX calls to send data to server, as data is too big to send in single request. But I want to save data to database in single transaction. If all data is saved then only commit otherwise rollback. is it possible to save all data in single transaction across multiple AJAX http requests ?

推荐答案

只是一个简短的想法:也许有一个临时表来存储这些项目.如果您满意它们的存在,则将它们一次推入正确的表中,或者将它们全部删除,然后重新开始.
Just a quick thought: perhaps have a transient table to store these items. When you are satisfied that they are all there then push them to the correct table in one go or delete them all and start again.


感谢您的回答.这是一种方法,但是我不能使用临时表来存储数据,因为我必须更新7个不同的表才能进行更新.请给我一些替代解决方案.急切地等待解决方案.
Thanks for the answer. It is a way to do that but I cannot use temparary table for storing data as I have to update 7 defferent tables to update. Please give me some alternate solution. Eagerly waiting for solution.


我不是说临时的,我说的是瞬态的:这意味着数据是瞬态的,而不是表! (也许我应该更清楚一些).抽入数据(为每个记录分配一个标识整个集合的密钥-可能是在过程开始时创建的GUID),一旦过程准备就绪(无论您决定如何),就可以运行存储的proc(例如)将对您使用该特定数据集执行任何操作,从而可以将更多数据随意散布到临时表中.
I didn''t say temporary, I said transient: meaning the data is transient, not the table! (Perhaps I should have been clearer). Pump the data in (assigning each record a key that identifies the entire set - perhaps a guid created at the start of the process) and, once the process is ready (however you decide that) you can then run a stored proc (for instance) that will do whatever it is you do with that specific set of data leaving you free to sprinkle more data into the transient table.


这篇关于跨多个HTTP请求的单个数据库事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆