0

我创建了 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");

在这里,我必须在运行时获取文件名,而不是通过硬编码

4

2 回答 2

0

以下代码将执行给定文件夹中的所有包。

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());
}
于 2013-06-28T16:12:05.203 回答
0

来自 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 });
    }
}
于 2018-07-25T06:32:06.460 回答