如何使用SSIS API将ComObject转换为SSIS数据类型ExecutePackageTask?

时间:2019-01-03 19:58:52

标签: .net ssis interop

我有一个SSIS包,该包的主“数据流”选项卡上包含一个“ ExecutePackageTask”元素。我试图使用SSIS API准备软件包中的信息,但遇到一个问题,我无法将软件包的Task.InnerObject从_COMObject类型转换为特定类型。

我设置了对以下dll的引用

C:\ Program Files(x86)\ Microsoft Visual Studio \ 2017 \ Professional \ Common7 \ IDE \ CommonExtensions \ Microsoft \ SSIS \ 140 \ Binn \ Microsoft.SqlServer.ExecPackageTaskWrap.dll

其中定义了ExecutePackageTaskClass类型。

if (taskHost.InnerObject is ExecutePackageTaskClass ||
    taskHost.InnerObject is ExecutePackageTask ||
    taskHost is IDTSExecutePackage100)
                        {
    //Never enters this block because it doesn't identify the type of the __Combject
    //However, if I force the execution down this path the properties on the object appear to match that of the ExecutePackageTaskClass
    foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(taskHost.InnerObject))
    {
        Console.WriteLine(prop.Name);
    }
}

这是使用记事本在DTSX文件中对象的XML的样子:

 <DTS:Executables>
    <DTS:Executable
      DTS:refId="Package\Call SplitPackageAny"
      DTS:ExecutableType="SSIS.ExecutePackageTask.3"
      DTS:TaskContact="Microsoft Corporation; Microsoft SQL Server v10; (C) 2007 Microsoft Corporation; All Rights Reserved;http://www.microsoft.com/sql/support/default.asp;1"
      DTS:LocaleID="-1"
      DTS:ObjectName="Call SplitPackageAny"
      DTS:DTSID="{0AAB5947-6897-48EF-B5EC-D9BFFC6F9BFE}"
      DTS:Description="Execute Package Task"
      DTS:CreationName="SSIS.ExecutePackageTask.3">
      <DTS:Variables />
      <DTS:ObjectData>
        <ExecutePackageTask>
          <Connection>{D84DFA79-A175-4E40-80E5-CC79B005F26C}</Connection>
        </ExecutePackageTask>
      </DTS:ObjectData>
    </DTS:Executable>

https://docs.microsoft.com/en-us/dotnet/api/microsoft.sqlserver.dts.tasks.executepackagetask.executepackagetaskclass?view=sqlserver-2017

? taskHost.InnerObject.GetType().Name
"__ComObject"

我该怎么做才能获得强类型对象?我在许多其他SSIS对象上都取得了成功。

0 个答案:

没有答案