脚本组件在执行后阶段失败,并返回错误代码0x80004002

时间:2017-09-27 08:59:17

标签: c# ssis

SSIS pakage抛出错误“** [SSIS.Pipeline]错误:脚本组件在执行后阶段失败并返回错误代码0x80004002。

**” 在脚本组件中,它显示任务成功运行但控制流任务显示错误。

Control flow task

Data flow Task

这是我的脚本任务代码:

public override void CreateNewOutputRows()
{
    #region Getting Variable values 

    // Getting DBPackage variable value. 
    Object varDBPackage;
    IDTSVariables100 vars = null;
    VariableDispenser.LockForRead("User::DBPackage");
    VariableDispenser.GetVariables(out vars);

    // Getting ReportPath variable value. 
    Object varReportPath;
    IDTSVariables100 ReportPath = null;
    VariableDispenser.LockForRead("User::ReportPath");
    VariableDispenser.GetVariables(out ReportPath);

    // Getting GetAllProvidersOutput variable value. 
    Object varGetAllProvidersOutput;
    IDTSVariables100 GetAllProvidersOutput = null;
    VariableDispenser.LockForRead("User::GetAllProvidersOutput");
    VariableDispenser.GetVariables(out GetAllProvidersOutput);

    DataTable dt = new DataTable();
    OleDbDataAdapter da = new OleDbDataAdapter();
    try
    {
        // Assign values into variable
        varDBPackage = (Object)vars["User::DBPackage"].Value;
        varReportPath = ReportPath["User::ReportPath"].Value;
        varGetAllProvidersOutput = GetAllProvidersOutput["User::GetAllProvidersOutput"].Value;

        // Extract the data from the object variable into the table and fetching Description from XML.
        da.Fill(dt, varDBPackage);


    }
    catch (Exception ex)
    {
        varDBPackage = null;
        varReportPath = null;
        varGetAllProvidersOutput = null;
    }
    finally
    {
        vars.Unlock();
        ReportPath.Unlock();
        GetAllProvidersOutput.Unlock();
    }

    #endregion

    String GetAllProvidersOutputPath = String.Format(@"{0}\{1}", varReportPath.ToString(), Convert.ToString(varGetAllProvidersOutput));
    var xDoc = XDocument.Load(GetAllProvidersOutputPath);
    var prefix = xDoc.Root.GetNamespaceOfPrefix("d1p1");

    foreach (DataRow item in dt.Rows)
    {
        string code = item["CODPROVIDERCODE"].ToString().ToUpper();
        string submissionEndDate = item["MAXSUBMISSIONENDDATE"].ToString();
        var node = xDoc.Root.Element(prefix + "AARetrieve")
        .Elements(prefix + "Organization")
        .FirstOrDefault(x => x.Attribute(prefix + "Code").Value.ToUpper() == code);

        string description = string.Empty;
        if (node != null)
            description = node.Elements(prefix + "OrganizationData").FirstOrDefault().Elements().Select(x => x.Attribute("Description").Value).FirstOrDefault();

        Output0Buffer.AddRow();
        Output0Buffer.CODPROVIDERCODE = (item["CODPROVIDERCODE"].ToString());
        Output0Buffer.MAXSUBMISSIONENDDATE = Convert.ToDateTime(item["MAXSUBMISSIONENDDATE"]);
        Output0Buffer.PROVIDERDESCRIPTION = description;
    }
}

错误:

[Script Component [23]]错误:System.InvalidCastException:无法将类型为“System .__ ComObject”的COM对象强制转换为接口类型“Microsoft.SqlServer.Dts.Runtime.Wrapper.IDTSVa​​riables100”。此操作失败,因为对于具有IID“{D1A469BC-F371-4D15-832F-BACB50C162E9}”的接口的COM组件上的QueryInterface调用由于以下错误而失败:应用程序调用了为不同线程编组的接口。 (来自HRESULT的异常:0x8001010E(RPC_E_WRONG_THREAD))。    在Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.HandleUserException(例外e)    在Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.PostExecute()    在Microsoft.SqlServer.Dts.Pipeline.ManagedComponentHost.HostPostExecute(IDTSManagedComponentWrapper100包装器)

我是SSIS的新手,所以请指导我导致问题的原因。

谢谢

0 个答案:

没有答案