如何执行从C#多个SSIS包(how to execute multiple ssis packag

2019-10-30 04:07发布

我已经创建了10级不同的包,我想从C#代码执行。 有人可以张贴一些屏幕截图来实现这一目标。 我曾经尝试这样做

Application app = new Application();
        TraceService("loading system From File system");
        //Create package Container to hold the package.
        //And Load the Package Using the Application Object.
        Package package = app.LoadPackage(@"C:\User\Kiran\Documents\Visual Studio 2012\Projects\WindowsServiceTest\WindowsServiceTest\Package1.dtsx", null);

        TraceService("Execution Started");
        DTSExecResult result = package.Execute();
        // print the result
        TraceService(result.ToString());
        TraceService("Execution Completed");

在这里,我通过硬编码来获得在运行时文件名不

Answer 1:

下面的代码会从指定文件夹执行所有的包。

var pkgLocation = @"C:\User\Kiran\Documents\Visual Studio 2012\Projects\WindowsServiceTest\WindowsServiceTest\";
foreach (var file in Directory.EnumerateFiles(pkgLocation, "*.dtsx"))
using (var pkg = new Application().LoadPackage(file, null))
{
   var pkgResults = pkg.Execute();
  Console.WriteLine("Package File Name:{0}, Result:{1}",file.ToString(), pkgResults.ToString());
}


Answer 2:

从C#和VB的执行SSIS包中是有据可查的官方网站 。 这是我在脚本任务完成代码执行多个SSIS包。

string packagesFolder = Dts.Variables["User::packagesFolder"].Value.ToString();
string rootFolder = Dts.Variables["User::rootFolder"].Value.ToString();

Package pkg;
Microsoft.SqlServer.Dts.Runtime.Application app;
DTSExecResult pkgResults;

foreach (var pkgLocation in Directory.EnumerateFiles(packagesFolder+"\\", "ValidateDataMigration-*.dtsx"))
{
    try
    {
        app = new Microsoft.SqlServer.Dts.Runtime.Application();
        pkg = app.LoadPackage(pkgLocation, null);
        pkgResults = pkg.Execute();

        File.AppendAllText(rootFolder + "\\DataValidationProgress.log", pkgLocation.ToString()+"=>"+ pkgResults.ToString()+ Environment.NewLine);
    }
    catch(Exception e)
    {
        File.AppendAllLines(rootFolder + "\\DataValidationErrors.log", new string[] { e.Message, e.StackTrace });
    }
}


文章来源: how to execute multiple ssis packages from c#
标签: c# ssis