简体   繁体   English

触发器是否异步(在SQL Server 2008 R2的asp.net命令对象上)

[英]Are triggers asynchronous (on asp.net command object for SQL Server 2008 R2 )

I have some additional (archival) data processing that needs to happen on a SQL Server Update call from ASP.net web app. 我还需要在ASP.net Web应用程序的SQL Server Update调用中进行一些其他(存档)数据处理。

I would like to run that independent from the web thread that calls the sql update Command (using the command Object call (not Async) for SQL Server 2008 R2). 我想独立于调用sql update命令的Web线程运行该命令(使用SQL Server 2008 R2的命令对象调用(非异步))。

All documentation I have read seems to indicate that a SQL Server trigger will not be running asynchronously, meaning that my web thread will be waiting for the update as well as the trigger to finish executing. 我阅读的所有文档似乎都表明SQL Server触发器将不会异步运行,这意味着我的Web线程将等待更新以及触发器完成执行。 Can anyone confirm this? 有人可以确认吗? Would like to know before I implement an independent async call for my archival sql command. 在我为档案sql命令实施独立的异步调用之前,我想知道。

The trigger is run in the same context and the same transaction as the SQL operation that fired the trigger, eg in the same context and transaction as your UPDATE statement. 触发器在与触发触发器的SQL操作相同的上下文和相同的事务中运行,例如,在与UPDATE语句相同的上下文和事务中运行。 The transaction (and thus the call from your ASP.NET code) doesn't terminate until the trigger has been executed. 直到执行触发器,事务(以及来自ASP.NET代码的调用)才会终止。 That's one of the main reasons why triggers should be used sparingly, and if used, the trigger must be very small, nimble and fast - do NOT do any heavy lifting and extensive processing and external calls in a trigger! 这就是为什么触发器应谨慎使用的主要原因之一,如果使用触发必须非常小,灵活和快速的- 不要做任何繁重的工作和广泛的处理,并在触发外部调用!

A trigger is part of the transaction that ended up calling the trigger. 触发器是事务的一部分,最终导致调用该触发器。 If you want something to happen outside the transaction, you might want to populate a field (archivestatus, default value 0) that states the record is not archived and then run a job that runs every so often (the timing depends on how many records you need to process and how soon the data needs to be archived) minutes that archives records which have not yet been archived and then updates the field. 如果您希望事务外发生某些事情,则可能需要填充一个字段(archivestatus,默认值为0),该字段指出记录未存档,然后运行一个经常运行的作业(时间取决于您记录的数量)需要处理的时间以及需要将数据存档的时间)来存档尚未存档的记录的分钟,然后更新该字段。 YOu might also need a trigger to update the record form archived to unarchived status if there are changes to the record. 如果记录有更改,您可能还需要触发器来将存档的记录表单更新为未存档状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM