【问题标题】:PostExecute() Output Buffer Foreach RowsPostExecute() 输出缓冲区 Foreach 行
【发布时间】:2017-05-18 02:48:58
【问题描述】:

我在 SSIS 的脚本组件中有以下代码。

我正在尝试反序列化 JSON 输出并将响应输出到数据库。

反序列化部分正在返回响应。

但是我得到一个“对象引用未设置为实例 对象。”OutputBuffer.AddRow() 上的错误;

我在兜圈子。我做错了什么?

public class ScriptMain : UserComponent
{

   public override void PostExecute()
    {
        base.PostExecute();

        string vOpportunityURL = Variables.pardotopportunityurl;
        System.Windows.Forms.MessageBox.Show(vOpportunityURL);

        int vMaxOpportunityId = Variables.pardotopportunitymaxid;
        System.Windows.Forms.MessageBox.Show(Convert.ToString(vMaxOpportunityId));

        int vProcessedRecordCount = Variables.pardotrecordcnt;
        System.Windows.Forms.MessageBox.Show(Convert.ToString(vProcessedRecordCount));

        var vProcessDate = Variables.pardotprocessdt;
        System.Windows.Forms.MessageBox.Show(Convert.ToString(vProcessDate));

        RootObject oppOutputResponse = GetWebServiceResult(vOpportunityURL);

        foreach (Opportunity op in oppOutputResponse.result.opportunity)
        {

            OpportunityDataBuffer.AddRow();
            OpportunityDataBuffer.ID = op.id;
            System.Windows.Forms.MessageBox.Show(Convert.ToString(op.id));
            OpportunityDataBuffer.Name = op.name;
            System.Windows.Forms.MessageBox.Show(Convert.ToString(op.name));

        }


    }


    private RootObject GetWebServiceResult(string vOpportunityURL)
    { 
        // Create API WEeb Service Request

        HttpWebRequest opportunityFullDataReq = (HttpWebRequest)WebRequest.Create(vOpportunityURL);

        var opportunityDataPostStr = "user_key=";
            opportunityDataPostStr += Variables.pardotauthusrkey;
            opportunityDataPostStr += "&api_key=";
            opportunityDataPostStr += Variables.pardotapikey;
            opportunityDataPostStr += "&output=full";
            opportunityDataPostStr += "&format=json";
            opportunityDataPostStr += "&sort_by=id";
            opportunityDataPostStr += "&sort_order=ascending";
            opportunityDataPostStr += "&id_greater_than=";
            opportunityDataPostStr += Variables.pardotopportunitymaxid;

            System.Windows.Forms.MessageBox.Show(Convert.ToString(opportunityDataPostStr));
            System.Windows.Forms.MessageBox.Show(vOpportunityURL + Convert.ToString(opportunityDataPostStr));

        var opportunityPostStream = Encoding.ASCII.GetBytes(opportunityDataPostStr);

        opportunityFullDataReq.Method = "POST";
        opportunityFullDataReq.ContentType = "application/x-www-form-urlencoded";
        opportunityFullDataReq.ContentLength = opportunityPostStream.Length;

        using(var opportunityStream = opportunityFullDataReq.GetRequestStream())
        {
            opportunityStream.Write(opportunityPostStream, 0, opportunityPostStream.Length);
        }

        // Capture Web Service Respose

        HttpWebResponse opportunityFullDataResponse = (HttpWebResponse)opportunityFullDataReq.GetResponse();

        RootObject opportunityWSResponse = null;

        Stream opportunityJsonStream = opportunityFullDataResponse.GetResponseStream();
        string wsResponseString = null;

        using (StreamReader wsResponseReader = new StreamReader(opportunityJsonStream))
        {
            wsResponseString = wsResponseReader.ReadToEnd();
            wsResponseReader.Close();
        }

        JavaScriptSerializer wsResponseJson = new JavaScriptSerializer();

        //var serialJsonResponseString = wsResponseJson.Serialize(wsResponseString);
        System.Windows.Forms.MessageBox.Show(wsResponseString.ToString());

        opportunityWSResponse = wsResponseJson.Deserialize<RootObject>(wsResponseString);

        return opportunityWSResponse;
   }

【问题讨论】:

    标签: c# ssis script-component


    【解决方案1】:

    输出缓冲区在 PostExecute 中不存在。

    在调用方法将内容添加到缓冲区之前,您可以检查最后一行是否已通过缓冲区。

    这里有类似的问题:Can I add rows to Output Buffer in SSIS Script Component in PostExecute?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-26
      • 2020-05-16
      • 2014-09-26
      相关资源
      最近更新 更多