简体   繁体   English

SSIS包-通过不同的连接循环执行Execute SQL任务

[英]SSIS package - loop through different connections for Execute SQL task

I am creating an MSSQL2008 SSIS package to generate and email reports from database tables. 我正在创建一个MSSQL2008 SSIS包,以从数据库表生成报告并通过电子邮件发送报告。 It works perfectly on a single database. 它可以在单个数据库上完美运行。 The client is running 3 different databases used by 3 different divisions. 客户端正在运行3个不同部门使用的3个不同数据库。 The database structure is exactly the same. 数据库结构完全相同。 All three databases are located on the same server, same security / credentials are used. 所有三个数据库都位于同一服务器上,使用相同的安全性/凭据。

I created a "For Each Loop Container" in my SSIS package that loops through the list of 3 items and populates it into a variable. 我在SSIS包中创建了一个“ For Each Loop Container”,用于遍历3个项目的列表并将其填充到变量中。 How do I now take that and pass it to the "Execute SQL Task" to run three times (once for each database)? 现在,我该如何将其传递给“执行SQL任务”以运行3次(每个数据库一次)?

Thank you for your time! 感谢您的时间!

It was a lot easier than I expected. 这比我预期的要容易得多。

I went to Properties of the "Execute SQL Task" and under "Expressions" for "Connection" I specified @varDBName, which was the variable I populated in the outer "for each" loop. 我转到“执行SQL任务”的属性,并在“连接”的“表达式”下指定了@varDBName,这是我在外部“ for each”循环中填充的变量。 I also needed to set "DelayValidation" property to "True" so it's only evaluated during run-time. 我还需要将“ DelayValidation”属性设置为“ True”,以便仅在运行时对其进行评估。 I hope this helps somebody else. 我希望这对其他人有帮助。

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

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