简体   繁体   English

如何在触发器中执行SQL Server中安装的SSIS包

[英]How to execute SSIS package installed in SQL Server in trigger

I have created SSIS package in SQL Server Business Intelligence Development Studio. 我在SQL Server Business Intelligence Development Studio中创建了SSIS包。 The package works fine if I run it there, so I deployed the package. 如果我在那里运行它,该包工作正常,所以我部署了包。

Then I used the package installation wizard and installed it on a local SQL Server 2005. 然后我使用了软件包安装向导并将其安装在本地SQL Server 2005上。

Now I want to use it in my trigger. 现在我想在触发器中使用它。

I know how to execute a package from file, but how to I execute it when it is installed in SQL Server? 我知道如何从文件中执行包,但是如何在SQL Server中安装它时执行它?

Thank you. 谢谢。

As I mentioned before: I would not put such a task into a trigger. 正如我之前提到的:我不会将这样的任务置于触发器中。 Since you cannot control when and how many times the trigger is fired, anything in the trigger should be very short in terms of execution time. 由于您无法控制触发器触发的次数和次数,因此触发器中的任何内容在执行时间方面都应该非常短。 Do not put long-running processing into a trigger! 不要把长时间运行加工成触发!

My approach would be: 我的方法是:

  1. the trigger writes an entry into a table (a "job" table or whatever you want to call it) 触发器将一个条目写入一个表(一个“作业”表或任何你想要调用它的表)

  2. a task (eg SQL Agent Job) that runs eg every 5 mins. 一个任务(例如SQL代理作业),例如每5分钟运行一次。 or whatever reads that table, and if necessary, writes the file. 或读取该表的任何内容,如有必要,写入该文件。

This decouples the trigger code from the longer process of actually writing the file. 这将触发器代码与实际写入文件的较长过程分离。

Otherwise, your system performance will be severely affected in a bad way by this potentially very long-running trigger.... 否则,这种可能非常长时间运行的触发器会严重影响您的系统性能......

There is a way to execute SSIS-packages from T-SQL, but a quite unsave one, i think. 有一种方法可以从T-SQL执行SSIS包,但我认为这是一种非常不可靠的方法。 It involves enabling the "xp_cmdshell" option and using dtexec. 它涉及启用“xp_cmdshell”选项并使用dtexec。 But that's definetly not for use in a trigger! 但这绝对不是用于触发器! Any way, as marc_s pointed out in his comment, a trigger should be very lean. 无论如何,正如marc_s在评论中指出的那样,触发器应该非常精简。 Since it is part of the transaction of the triggering command any long running operation, especially a SSIS package, would slow your database down considerably. 由于它是触发命令事务的一部分,因此任何长时间运行的操作(尤其是SSIS包)都会大大降低数据库的速度。

I'd break this out into separate steps. 我将其分解为单独的步骤。 The file requirement may be there, but consider this: as long as every row generates a file, is it truly a deal-breaker if it takes perhaps five or ten minutes to create the file? 文件要求可能存在,但请考虑这一点:只要每行生成一个文件,如果创建文件需要五到十分钟,它真的是一个交易破坏者吗? And is this worse than the knock-on effects you'll see from running a SSIS package from within the trigger? 这比从触发器中运行SSIS包时看到的连锁效应更糟吗?

So: 所以:

Step 1 : the trigger simply inserts a row into another table with the information required for the file to be created. 步骤1:触发器只是将一行插入另一个表中,其中包含要创建的文件所需的信息。
Step 2 : modify your SSIS package to have an extra early step that polls that table for any new entries, creates the files as needed, then marks the entries as completed (or removes them completely, but personally I like audit trails). 第2步:修改您的SSIS包以进行额外的早期步骤,轮询该表以查找任何新条目,根据需要创建文件,然后将条目标记为已完成(或完全删除它们,但我个人喜欢审计跟踪)。
Step 3 : add a scheduled job to the server that runs that SSIS package every 5 minutes. 步骤3:将计划作业添加到每5分钟运行该SSIS包的服务器。

If you don't want to modify your SSIS package, you could instead create a stored procedure that polls the table and executes the package, and schedule that in a job. 如果您不想修改SSIS包,则可以创建一个存储过程来轮询表并执行包,并在作业中安排该包。 The main thing is to get away from the idea of firing the package direct from the trigger. 主要的是摆脱从触发器直接触发包的想法。

The method above will also minimize the impact of potential problems such as the file destination being unavailable for some reason. 上述方法还将最小化潜在问题的影响,例如由于某种原因文件目的地不可用。

just complementing all other answers, you should definitively not do that. 只是补充所有其他答案,你应该明确地不这样做。 marc_s's idea of inserting data into a table and having a job every X minutes is the best apporach in my opinion. 在我看来,marc_s将数据插入表格并每隔X分钟就有一份工作的想法是最好的选择。

PS1: Here is a link on how to call a package from a SP PS1: 是一个如何从SP调用包的链接

PS2: Ansering your other questiom, to call a package stored on SQl using DTEXEC, just replace /FILE to /SQL PS2:回避您的其他问题,使用DTEXEC调用存储在SQl上的包,只需将/FILE替换为/SQL

dtexec /sql "\YourPackage"

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

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