0

我有一个可以在 BIDS(或任何 MS 现在为 SSIS 调用 VS)和执行包实用程序中运行良好的包。

我尝试使用以下代码从 C# 运行它,但没有任何反应。.Execute 返回成功,ExecutionStatus 已完成。.Execute 需要几秒钟,而它应该需要一两分钟,并且它没有做它应该做的事情(加载源文件,将它们移动到其他地方等)

var pkgLocation = @"C:\ImportMetricsPackage.dtsx";
var app = new Microsoft.SqlServer.Dts.Runtime.Application();
var pkg = app.LoadPackage(pkgLocation, null);
var pkgResults = pkg.Execute();

我错过了什么?

4

1 回答 1

4

您是否尝试过捕获包事件?

MyEventListener eventListener = new MyEventListener();

var pkgLocation = @"C:\ImportMetricsPackage.dtsx";
var app = new Microsoft.SqlServer.Dts.Runtime.Application();
pkg = app.LoadPackage(pkgLocation, eventListener);
pkgResults = pkg.Execute(null, null, eventListener, null, null);

事件监听类:

class MyEventListener : DefaultEvents
{
    public override bool OnError(DtsObject source, int errorCode, string subComponent, 
    string description, string helpFile, int helpContext, string idofInterfaceWithError)
    {
        // Add application-specific diagnostics here.
        Console.WriteLine("Error in {0}/{1} : {2}", source, subComponent, description);
        return false;
    }
}

有关更多详细信息,请参阅以编程方式加载和运行本地包

于 2012-12-19T22:54:33.663 回答