[英]SQL Server invoke action on insert rows that will add data to another table async from C#
I have C# process that insert rows to table in SQL Server 2012. 我有C#进程在SQL Server 2012中向表中插入行。
I want to insert tracking information to another 2 tables as a result with a specific logic. 我想通过特定逻辑将跟踪信息插入到另外2个表中。
I thought about 3 ways to do it: 我考虑了3种方法:
Create stack/collection to will collect the data and will insert by Entity Framework each X seconds/mili. 创建堆栈/集合以收集数据,并每隔X秒/英里由Entity Framework插入一次。
SQL Server trigger that will listen to events on the table and will insert the data to another table. SQL Server触发器将侦听表上的事件并将数据插入到另一个表中。 In case of trigger the action will be synchronized and will slow the operation. 在触发的情况下,动作将被同步并且将降低操作速度。
Async trigger action - Trigger on the table that will send to the service broker queue and will execute it async by procedure. 异步触发操作-在将发送到服务代理队列并按过程异步执行的表上触发。
What is the best way or maybe there is another way? 最好的方法是什么,也许还有另一种方法?
Unless you are confident that the overhead on insert in case 2. is unacceptable, go with it. 除非您确信情况2中插入的开销是不可接受的,否则请选择它。 This way your solution is as good as having two more inserts each time/in the same transaction an insert to the main table is performed. 这样,您的解决方案就像每次有两个以上的插入操作一样好/在同一事务中执行对主表的插入操作。
Thus you will be sure you are not missing inserts due to some unavoidable failure and no need to worry about restarting copy process. 因此,您将确保不会因为某些不可避免的故障而不会丢失插入内容,并且无需担心重新启动复制过程。
I would personally start with this solution first, profile and only then consider other options. 我个人将首先从此解决方案开始,然后介绍配置文件,然后再考虑其他选项。 Actually, I am going to use it in a project of my own. 实际上,我将在自己的项目中使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.