是否可以进行仍允许只读请求的事务?
我目前有一个批处理过程,运行可能需要一个小时。它不是数据库密集型的,只是有很多事情要做,比如网络调用。
我有一个事务围绕着整个事情,所以如果出现任何问题,我会回滚。
是否可以进行此事务,使其仅阻止写入数据库而不是只读的请求?如果没有,为什么不呢?这只是数据库的自然限制吗?
我使用的是 .net 4.0,并且使用 TransactionScope
来完成此任务。
I have a batch process at the moment and it can take up to an hour to run. It's not database intensive, it's just that there's a lot of things like web calls it's got to do.
I have a transaction wrapped around the whole thing so if anything goes wrong, I will roll back.
Is it possible to make this transaction so it only blocks requests which write to the database and not Read Only? If not, why not? Is this just a natural limitation of the database?
I'm in .net 4.0 and I'm using a TransactionScope
for this task.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要这样做。加载到暂存表中。操作完成后,将其批量传输到实际表中。
Don't do this. Load into a staging table. When the operation completes, bulk transfer it over to the actual table.
一般来说,这样的事情根本不会成功。默认情况下,大多数资源管理器不会让事务持续那么长时间,如果他们这样做(并且涉及多个资源管理器),那么根据正在更新/修改的数据量,提交事务的行为可能需要非常很长时间。
如果您只是想在过程中阻止数据库访问,那么最好在数据库中设置一个标志,然后在设置该标志时使应用程序中的其他功能失败。
应用程序的范围可能会影响标志的存储位置;如果只有一个实例在运行,则可以将标志存储在内存中,但如果有多个实例,则可能每次都必须检查数据库。
Generally, something like this is not going to succeed at all; most resource managers by default won't let a transaction go on for that long, and if they did (and if multiple resource managers are involved) then depending on the amount of data that is being updated/modified, the act of committing a transaction could take a very long time.
If you are just looking to block out database access during your process, you are better off setting a flag in the database and then having other functions in your application fail if the flag is set.
The scope of your application can affect where the flag is stored; if you only have one instance running, you can store the flag in memory, but if there are multiple instances, you probably have to check the database every time.