首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >用于收集谱系ID的SSIS脚本任务

用于收集谱系ID的SSIS脚本任务
EN

Stack Overflow用户
提问于 2019-03-21 22:02:16
回答 1查看 313关注 0票数 1

我有一个收集扩展错误信息的SSIS脚本任务。

脚本的内容如下:

代码语言:javascript
运行
复制
/// <summary>
/// ScriptMain is the entry point class of the script.  Do not change the name, attributes,
/// or parent of this class.
/// </summary>
[Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]

public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{

    Dictionary<string, string> lineageIds = null;

    public void Main()
    {
        // Grab the executables so we have to something to iterate over, and initialize our lineageIDs list
        // Why the executables?  Well, SSIS won't let us store a reference to the Package itself...
        Dts.Variables["User::execsObj"].Value = ((Package)Dts.Variables["User::execsObj"].Parent).Executables;
        Dts.Variables["User::lineageIds"].Value = new Dictionary<string, string>();
        lineageIds = (Dictionary<string, string>)Dts.Variables["User::lineageIds"].Value;
        Executables execs = (Executables)Dts.Variables["User::execsObj"].Value;

        ReadExecutables(execs);

        Dts.TaskResult = (int)ScriptResults.Success;
    }

    private void ReadExecutables(Executables executables)
    {
        foreach (Executable pkgExecutable in executables)
        {
            if (object.ReferenceEquals(pkgExecutable.GetType(), typeof(Microsoft.SqlServer.Dts.Runtime.TaskHost)))
            {
                TaskHost pkgExecTaskHost = (TaskHost)pkgExecutable;
                if (pkgExecTaskHost.CreationName.StartsWith("SSIS.Pipeline"))
                {
                    ProcessDataFlowTask(pkgExecTaskHost);
                }
            }
            else if (object.ReferenceEquals(pkgExecutable.GetType(), typeof(Microsoft.SqlServer.Dts.Runtime.ForEachLoop)))
            {
                // Recurse into FELCs
                ReadExecutables(((ForEachLoop)pkgExecutable).Executables);
            }
        }
    }

    private void ProcessDataFlowTask(TaskHost currentDataFlowTask)
    {
        MainPipe currentDataFlow = (MainPipe)currentDataFlowTask.InnerObject;
        foreach (IDTSComponentMetaData100 currentComponent in currentDataFlow.ComponentMetaDataCollection)
        {
            // Get the inputs in the component.
            foreach (IDTSInput100 currentInput in currentComponent.InputCollection)
                foreach (IDTSInputColumn100 currentInputColumn in currentInput.InputColumnCollection)
                    lineageIds.Add(currentDataFlowTask.ID.ToString() + currentInputColumn.ID, currentInputColumn.Name);

            // Get the outputs in the component.
            foreach (IDTSOutput100 currentOutput in currentComponent.OutputCollection)
                foreach (IDTSOutputColumn100 currentoutputColumn in currentOutput.OutputColumnCollection)
                    lineageIds.Add(currentDataFlowTask.ID.ToString() + currentoutputColumn.ID, currentoutputColumn.Name);
        }
    }

    enum ScriptResults
    {
        Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
        Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
    };
}

这曾经在SQL Server 2014上正常工作。但是,由于升级到SQL server 2017,该任务在线上显示以下错误消息:

代码语言:javascript
运行
复制
MainPipe currentDataFlow = (MainPipe)currentDataFlowTask.InnerObject;

ST_47767930511349f4b94ba74c27240570中发生了类型为“System.InvalidCastException”的异常,但未在用户代码中进行处理

其他信息:无法将类型为“System.__ComObject”的COM对象强制转换为接口类型'Microsoft.SqlServer.Dts.Pipeline.Wrapper.MainPipe'.此操作失败,原因是由于以下错误,对COM组件的QueryInterface调用失败:不支持此类接口(来自HRESULT的异常: 0x80004002 (E_NOINTERFACE))。

在升级到SQL Server 2017之后,还有没有人看到过这种情况?

EN

回答 1

Stack Overflow用户

发布于 2019-03-22 00:28:01

原来,currentDataFlowTask.InnerObject返回的Com对象来自较新版本的Microsoft.SqlServer.DTSPipelineWrap。

为了解决这个问题,我删除了对Microsoft.SqlServer.DTSPipelineWrap的引用,并将其替换为同一程序集的版本14。

然后我修改了下面这一行:

代码语言:javascript
运行
复制
MainPipe currentDataFlow = (MainPipe)currentDataFlowTask.InnerObject;

代码语言:javascript
运行
复制
IDTSPipeline130 currentDataFlow = (IDTSPipeline130)currentDataFlowTask.InnerObject;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55282203

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档