Running SSIS Execute Package Task programmacticall

2019-05-31 12:56发布

I need to run an Execute Package Task programmatically in code. I get the following error:

Error in Microsoft.SqlServer.Dts.Runtime.TaskHost/ : 
There is no project to reference.
Error in Microsoft.SqlServer.Dts.Runtime.TaskHost: 
There were errors during task validation.
Failure

This error only occurs if I set the Execute Package Task ReferenceType to Project Reference.

However, if I set the ReferenceType to External Reference, the error does not occur and the packages are run successfully.

I need to know why this error occur and why can't I use Project Reference?

The following screen shot shows the setting which cause the error:

enter image description here

The below setting does not cause an error:

enter image description here

Lastly here is my code which runs the task programmatically:

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

    static void Main(string[] args)
    {
        string pkgLocation;
        Package pkg;

        Application app;
        DTSExecResult pkgResults;

        MyEventListener eventListener = new MyEventListener();

        pkgLocation =
            @"C:\Users\Administrator\Desktop\ExampleConnectionMgr\Master.dtsx";
        app = new Application();
        pkg = app.LoadPackage(pkgLocation, eventListener);
        pkgResults = pkg.Execute(null, null, eventListener, null, null);

        Console.WriteLine(pkgResults.ToString());
        Console.ReadKey();

    }
}

标签: c# ssis
1条回答
够拽才男人
2楼-- · 2019-05-31 13:25

This due to the face that you're executing the package outside the context of the SSIS project. The two .dtsx packages have no knowledge of each other. When you select "Project Reference" as a ReferenceType, the system looks for other package members of the same project, which is why DataExtractionB.dtsx is an available option.

查看更多
登录 后发表回答