首页 > 解决方案 > 缺少定义并且没有可访问的扩展名

问题描述

我正在尝试使用 SSIS 从 CMS Open Payment 网站导入 Web API。从 CMS 网站提取数据后,我想将其导入我的 SQL Prod 环境。但是,我遇到了两个问题。

  1. 每次我编辑脚本组件的代码时,我都必须手动将“内部字符串”代码添加到“Bufferwrapper.cs”模块类中,以避免出现“缺少定义且无法访问扩展”错误(尽管代码是自动生成并被覆盖的) )。有没有办法给出字段定义并将它们与可访问的扩展相关联?

这是我添加到 BufferWrapper 类以消除字段错误的代码示例

internal string Change_Type;
  1. 在我为每个字段手动将“内部字符串”代码添加到“Bufferwrapper.cs”模块类并尝试运行包后,它返回 1000 个空行而不是数据。我该如何纠正?

脚本代码

#region Namespaces
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
using System.Net;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.IO;
using System.Web.Script.Serialization;
#endregion



#region Class
[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
{

    public override void CreateNewOutputRows()
    {

        //Set Webservice URL
        string wUrl = "https://openpaymentsdata.cms.gov/resource/bqf5-h6wd.json";



        try
        {
            //Call getWebServiceResult to return our WorkGroupMetric array
            WorkGroupMetric[] outPutMetrics = GetWebServiceResult(wUrl);

            //For each group of metrics output records
            foreach (var metric in outPutMetrics)
            {
                Output0Buffer.AddRow();
                Output0Buffer.Change_Type = metric.CT;
                Output0Buffer.Covered_Recipient_Type = metric.CRT;
                Output0Buffer.Teaching_Hospital_CCN = metric.THC;
                Output0Buffer.Teaching_Hospital_ID = metric.THI;
                Output0Buffer.Teaching_Hospital_Name = metric.THN;
                Output0Buffer.Physician_Profile_ID = metric.PPI;
                Output0Buffer.Physician_First_Name = metric.PFN;
                Output0Buffer.Physician_Middle_Name = metric.PMN;
                Output0Buffer.Physician_Last_Name = metric.PLN;
                Output0Buffer.Physician_Name_Suffix = metric.PNS;
                Output0Buffer.Recipient_Primary_Business_Street_Address_Line1 = metric.RPB1;
                Output0Buffer.Recipient_Primary_Business_Street_Address_Line2 = metric.RPB2;
                Output0Buffer.Recipient_City = metric.RC;
                Output0Buffer.Recipient_State = metric.RS;
                Output0Buffer.Recipient_Zip_Code = metric.RZC;
                Output0Buffer.Recipient_Country = metric.RCO;
                Output0Buffer.Recipient_Province = metric.RP;
                Output0Buffer.Recipient_Postal_Code = metric.RPC;
                Output0Buffer.Physician_Primary_Type = metric.PPT;
                Output0Buffer.Physician_Specialty = metric.PS;
                Output0Buffer.Physician_License_State_code1 = metric.PLS1;
                Output0Buffer.Physician_License_State_code2 = metric.PLS2;
                Output0Buffer.Physician_License_State_code3 = metric.PLS3;
                Output0Buffer.Physician_License_State_code4 = metric.PLS4;
                Output0Buffer.Physician_License_State_code5 = metric.PLS5;
                Output0Buffer.Submitting_Applicable_Manufacturer_or_Applicable_GPO_Name = metric.SAM;
                Output0Buffer.Applicable_Manufacturer_or_Applicable_GPO_Making_Payment_ID = metric.AMOI;
                Output0Buffer.Applicable_Manufacturer_or_Applicable_GPO_Making_Payment_Name = metric.AMON;
                Output0Buffer.Applicable_Manufacturer_or_Applicable_GPO_Making_Payment_State = metric.AMOS;
                Output0Buffer.Applicable_Manufacturer_or_Applicable_GPO_Making_Payment_Country = metric.AMOC;
                Output0Buffer.Total_Amount_of_Payment_USDollars = metric.TAO;
                Output0Buffer.Date_of_Payment = metric.DOP;
                Output0Buffer.Number_of_Payments_Included_in_Total_Amount = metric.NOA;
                Output0Buffer.Form_of_Payment_or_Transfer_of_Value = metric.FOP;
                Output0Buffer.Nature_of_Payment_or_Transfer_of_Value = metric.NOP;
                Output0Buffer.City_of_Travel = metric.COT;
                Output0Buffer.State_of_Travel = metric.SOT;
                Output0Buffer.Country_of_Travel = metric.COOT;
                Output0Buffer.Physician_Ownership_Indicator = metric.POI;
                Output0Buffer.Third_Party_Payment_Recipient_Indicator = metric.TPP;
                Output0Buffer.Name_of_Third_Party_Entity_Receiving_Payment_or_Transfer_of_Value = metric.NOT;
                Output0Buffer.Charity_Indicator = metric.CHI;
                Output0Buffer.Third_Party_Equals_Covered_Recipient_Indicator = metric.TPE;
                Output0Buffer.Contextual_Information = metric.CI;
                Output0Buffer.Delay_in_Publication_Indicator = metric.DIP;
                Output0Buffer.Record_ID = metric.RI;
                Output0Buffer.Dispute_Status_for_Publication = metric.DSF;
                Output0Buffer.Related_Product_Indicator = metric.RPI;
                Output0Buffer.Covered_or_Noncovered_Indicator_1 = metric.CON1;
                Output0Buffer.Indicate_Drug_or_Biological_or_Device_or_Medical_Supply_1 = metric.IDO1;
                Output0Buffer.Product_Category_or_Therapeutic_Area_1 = metric.PCO1;
                Output0Buffer.Name_of_Drug_or_Biological_or_Device_or_Medical_Supply_1 = metric.NOD1;
                Output0Buffer.Associated_Drug_or_Biological_NDC_1 = metric.ADO1;
                Output0Buffer.Covered_or_Noncovered_Indicator_2 = metric.CON2;
                Output0Buffer.Indicate_Drug_or_Biological_or_Device_or_Medical_Supply_2 = metric.IDO2;
                Output0Buffer.Product_Category_or_Therapeutic_Area_2 = metric.PCO2;
                Output0Buffer.Name_of_Drug_or_Biological_or_Device_or_Medical_Supply_2 = metric.NOD2;
                Output0Buffer.Associated_Drug_or_Biological_NDC_2 = metric.ADO2;
                Output0Buffer.Covered_or_Noncovered_Indicator_3 = metric.CON3;
                Output0Buffer.Indicate_Drug_or_Biological_or_Device_or_Medical_Supply_3 = metric.IDO3;
                Output0Buffer.Product_Category_or_Therapeutic_Area_3 = metric.PCO3;
                Output0Buffer.Name_of_Drug_or_Biological_or_Device_or_Medical_Supply_3 = metric.NOD3;
                Output0Buffer.Associated_Drug_or_Biological_NDC_3 = metric.ADO3;
                Output0Buffer.Covered_or_Noncovered_Indicator_4 = metric.CON4;
                Output0Buffer.Indicate_Drug_or_Biological_or_Device_or_Medical_Supply_4 = metric.IDO4;
                Output0Buffer.Product_Category_or_Therapeutic_Area_4 = metric.PCO4;
                Output0Buffer.Name_of_Drug_or_Biological_or_Device_or_Medical_Supply_4 = metric.NOD4;
                Output0Buffer.Associated_Drug_or_Biological_NDC_4 = metric.ADO4;
                Output0Buffer.Covered_or_Noncovered_Indicator_5 = metric.CON5;
                Output0Buffer.Indicate_Drug_or_Biological_or_Device_or_Medical_Supply_5 = metric.IDO5;
                Output0Buffer.Product_Category_or_Therapeutic_Area_5 = metric.PCO5;
                Output0Buffer.Name_of_Drug_or_Biological_or_Device_or_Medical_Supply_5 = metric.NOD5;
                Output0Buffer.Associated_Drug_or_Biological_NDC_5 = metric.ADO5;
                Output0Buffer.Program_Year = metric.PY;
                Output0Buffer.Payment_Publication_Date = metric.PPD;

            }

        }
        catch (Exception e)
        {
            FailComponent(e.ToString());
        }

    }

    /// <summary>
    /// Method to return our WorkGroupMetric array
    /// </summary>
    /// <param name="wUrl">The web service URL to call</param>
    /// <returns>An array of WorkGroupMetric composed of the de-serialized JSON</returns>
    private WorkGroupMetric[] GetWebServiceResult(string wUrl)
    {

        ServicePointManager.Expect100Continue = true;
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
        HttpWebRequest httpWReq = (HttpWebRequest)WebRequest.Create(wUrl);
        HttpWebResponse httpWResp = (HttpWebResponse)httpWReq.GetResponse();
        WorkGroupMetric[] jsonResponse = null;

        try
        {
            //Test the connection
            if (httpWResp.StatusCode == HttpStatusCode.OK)
            {

                Stream responseStream = httpWResp.GetResponseStream();
                string jsonString = null;

                //Set jsonString using a stream reader
                using (StreamReader reader = new StreamReader(responseStream))
                {
                    jsonString = reader.ReadToEnd().Replace("\\", "");
                    reader.Close();
                }

                //Deserialize our JSON
                JavaScriptSerializer sr = new JavaScriptSerializer();
                //JSON string comes in with a leading and trailing " that need to be removed for parsing to work correctly
                //The JSON here is serialized weird, normally you would not need this trim
                jsonResponse = sr.Deserialize<WorkGroupMetric[]>(jsonString.Trim('"'));

            }
            //Output connection error message
            else
            {
                FailComponent(httpWResp.StatusCode.ToString());

            }
        }
        //Output JSON parsing error
        catch (Exception e)
        {
            FailComponent(e.ToString());
        }
        return jsonResponse;

    }

    /// <summary>
    /// Outputs error message
    /// </summary>
    /// <param name="errorMsg">Full error text</param>
    private void FailComponent(string errorMsg)
    {
        bool fail = false;
        IDTSComponentMetaData100 compMetadata = this.ComponentMetaData;
        compMetadata.FireError(1, "Error Getting Data From Webservice!", errorMsg, "", 0, out fail);

    }

}
#endregion

#region JSON Class
//Class to hold our work group metrics



class WorkGroupMetric
{
    private string Change_Type;
    private string Covered_Recipient_Type;
    private string Teaching_Hospital_CCN;
    private string Teaching_Hospital_ID;
    private string Teaching_Hospital_Name;
    private string Physician_Profile_ID;
    private string Physician_First_Name;
    private string Physician_Middle_Name;
    private string Physician_Last_Name;
    private string Physician_Name_Suffix;
    private string Recipient_Primary_Business_Street_Address_Line1;
    private string Recipient_Primary_Business_Street_Address_Line2;
    private string Recipient_City;
    private string Recipient_State;
    private string Recipient_Zip_Code;
    private string Recipient_Country;
    private string Recipient_Province;
    private string Recipient_Postal_Code;
    private string Physician_Primary_Type;
    private string Physician_Specialty;
    private string Physician_License_State_code1;
    private string Physician_License_State_code2;
    private string Physician_License_State_code3;
    private string Physician_License_State_code4;
    private string Physician_License_State_code5;
    private string Submitting_Applicable_Manufacturer_or_Applicable_GPO_Name;
    private string Applicable_Manufacturer_or_Applicable_GPO_Making_Payment_ID;
    private string Applicable_Manufacturer_or_Applicable_GPO_Making_Payment_Name;
    private string Applicable_Manufacturer_or_Applicable_GPO_Making_Payment_State;
    private string Applicable_Manufacturer_or_Applicable_GPO_Making_Payment_Country;
    private string Total_Amount_of_Payment_USDollars;
    private string Date_of_Payment;
    private string Number_of_Payments_Included_in_Total_Amount;
    private string Form_of_Payment_or_Transfer_of_Value;
    private string Nature_of_Payment_or_Transfer_of_Value;
    private string City_of_Travel;
    private string State_of_Travel;
    private string Country_of_Travel;
    private string Physician_Ownership_Indicator;
    private string Third_Party_Payment_Recipient_Indicator;
    private string Name_of_Third_Party_Entity_Receiving_Payment_or_Transfer_of_Value;
    private string Charity_Indicator;
    private string Third_Party_Equals_Covered_Recipient_Indicator;
    private string Contextual_Information;
    private string Delay_in_Publication_Indicator;
    private string Record_ID;
    private string Dispute_Status_for_Publication;
    private string Related_Product_Indicator;
    private string Covered_or_Noncovered_Indicator_1;
    private string Indicate_Drug_or_Biological_or_Device_or_Medical_Supply_1;
    private string Product_Category_or_Therapeutic_Area_1;
    private string Name_of_Drug_or_Biological_or_Device_or_Medical_Supply_1;
    private string Associated_Drug_or_Biological_NDC_1;
    private string Covered_or_Noncovered_Indicator_2;
    private string Indicate_Drug_or_Biological_or_Device_or_Medical_Supply_2;
    private string Product_Category_or_Therapeutic_Area_2;
    private string Name_of_Drug_or_Biological_or_Device_or_Medical_Supply_2;
    private string Associated_Drug_or_Biological_NDC_2;
    private string Covered_or_Noncovered_Indicator_3;
    private string Indicate_Drug_or_Biological_or_Device_or_Medical_Supply_3;
    private string Product_Category_or_Therapeutic_Area_3;
    private string Name_of_Drug_or_Biological_or_Device_or_Medical_Supply_3;
    private string Associated_Drug_or_Biological_NDC_3;
    private string Covered_or_Noncovered_Indicator_4;
    private string Indicate_Drug_or_Biological_or_Device_or_Medical_Supply_4;
    private string Product_Category_or_Therapeutic_Area_4;
    private string Name_of_Drug_or_Biological_or_Device_or_Medical_Supply_4;
    private string Associated_Drug_or_Biological_NDC_4;
    private string Covered_or_Noncovered_Indicator_5;
    private string Indicate_Drug_or_Biological_or_Device_or_Medical_Supply_5;
    private string Product_Category_or_Therapeutic_Area_5;
    private string Name_of_Drug_or_Biological_or_Device_or_Medical_Supply_5;
    private string Associated_Drug_or_Biological_NDC_5;
    private string Program_Year;
    private string Payment_Publication_Date;


    public string CT
    {
        get { return Change_Type; }
        set { Change_Type = value; }
    }

    public string CRT
    {
        get { return Covered_Recipient_Type; }
        set { Covered_Recipient_Type = value; }
    }

    public string THC
    {
        get { return Teaching_Hospital_CCN; }
        set { Teaching_Hospital_CCN = value; }
    }

    public string THI
    {
        get { return Teaching_Hospital_ID; }
        set { Teaching_Hospital_ID = value; }
    }

    public string THN
    {
        get { return Teaching_Hospital_Name; }
        set { Teaching_Hospital_Name = value; }
    }

    public string PPI
    {
        get { return Physician_Profile_ID; }
        set { Physician_Profile_ID = value; }
    }

    public string PFN
    {
        get { return Physician_First_Name; }
        set { Physician_First_Name = value; }
    }

    public string PMN
    {
        get { return Physician_Middle_Name; }
        set { Physician_Middle_Name = value; }
    }

    public string PLN
    {
        get { return Physician_Last_Name; }
        set { Physician_Last_Name = value; }
    }

    public string PNS
    {
        get { return Physician_Name_Suffix; }
        set { Physician_Name_Suffix = value; }
    }

    public string RPB1
    {
        get { return Recipient_Primary_Business_Street_Address_Line1; }
        set { Recipient_Primary_Business_Street_Address_Line1 = value; }
    }

    public string RPB2
    {
        get { return Recipient_Primary_Business_Street_Address_Line2; }
        set { Recipient_Primary_Business_Street_Address_Line2 = value; }
    }

    public string RC
    {
        get { return Recipient_City; }
        set { Recipient_City = value; }
    }

    public string RS
    {
        get { return Recipient_State; }
        set { Recipient_State = value; }
    }

    public string RZC
    {
        get { return Recipient_Zip_Code; }
        set { Recipient_Zip_Code = value; }
    }

    public string RCO
    {
        get { return Recipient_Country; }
        set { Recipient_Country = value; }
    }

    public string RP
    {
        get { return Recipient_Province; }
        set { Recipient_Province = value; }
    }

    public string RPC
    {
        get { return Recipient_Postal_Code; }
        set { Recipient_Postal_Code = value; }
    }

    public string PPT
    {
        get { return Physician_Primary_Type; }
        set { Physician_Primary_Type = value; }
    }

    public string PS
    {
        get { return Physician_Specialty; }
        set { Physician_Specialty = value; }
    }

    public string PLS1
    {
        get { return Physician_License_State_code1; }
        set { Physician_License_State_code1 = value; }
    }

    public string PLS2
    {
        get { return Physician_License_State_code2; }
        set { Physician_License_State_code2 = value; }
    }

    public string PLS3
    {
        get { return Physician_License_State_code3; }
        set { Physician_License_State_code3 = value; }
    }

    public string PLS4
    {
        get { return Physician_License_State_code4; }
        set { Physician_License_State_code4 = value; }
    }

    public string PLS5
    {
        get { return Physician_License_State_code5; }
        set { Physician_License_State_code5 = value; }
    }

    public string SAM
    {
        get { return Submitting_Applicable_Manufacturer_or_Applicable_GPO_Name; }
        set { Submitting_Applicable_Manufacturer_or_Applicable_GPO_Name = value; }
    }

    public string AMOI
    {
        get { return Applicable_Manufacturer_or_Applicable_GPO_Making_Payment_ID; }
        set { Applicable_Manufacturer_or_Applicable_GPO_Making_Payment_ID = value; }
    }

    public string AMON
    {
        get { return Applicable_Manufacturer_or_Applicable_GPO_Making_Payment_Name; }
        set { Applicable_Manufacturer_or_Applicable_GPO_Making_Payment_Name = value; }
    }

    public string AMOS
    {
        get { return Applicable_Manufacturer_or_Applicable_GPO_Making_Payment_State; }
        set { Applicable_Manufacturer_or_Applicable_GPO_Making_Payment_State = value; }
    }

    public string AMOC
    {
        get { return Applicable_Manufacturer_or_Applicable_GPO_Making_Payment_Country; }
        set { Applicable_Manufacturer_or_Applicable_GPO_Making_Payment_Country = value; }
    }

    public string TAO
    {
        get { return Total_Amount_of_Payment_USDollars; }
        set { Total_Amount_of_Payment_USDollars = value; }
    }

    public string DOP
    {
        get { return Date_of_Payment; }
        set { Date_of_Payment = value; }
    }

    public string NOA
    {
        get { return Number_of_Payments_Included_in_Total_Amount; }
        set { Number_of_Payments_Included_in_Total_Amount = value; }
    }

    public string FOP
    {
        get { return Form_of_Payment_or_Transfer_of_Value; }
        set { Form_of_Payment_or_Transfer_of_Value = value; }
    }

    public string NOP
    {
        get { return Nature_of_Payment_or_Transfer_of_Value; }
        set { Nature_of_Payment_or_Transfer_of_Value = value; }
    }

    public string COT
    {
        get { return City_of_Travel; }
        set { City_of_Travel = value; }
    }

    public string SOT
    {
        get { return State_of_Travel; }
        set { State_of_Travel = value; }
    }

    public string COOT
    {
        get { return Country_of_Travel; }
        set { Country_of_Travel = value; }
    }

    public string POI
    {
        get { return Physician_Ownership_Indicator; }
        set { Physician_Ownership_Indicator = value; }
    }

    public string TPP
    {
        get { return Third_Party_Payment_Recipient_Indicator; }
        set { Third_Party_Payment_Recipient_Indicator = value; }
    }

    public string NOT
    {
        get { return Name_of_Third_Party_Entity_Receiving_Payment_or_Transfer_of_Value; }
        set { Name_of_Third_Party_Entity_Receiving_Payment_or_Transfer_of_Value = value; }
    }

    public string CHI
    {
        get { return Charity_Indicator; }
        set { Charity_Indicator = value; }
    }

    public string TPE
    {
        get { return Third_Party_Equals_Covered_Recipient_Indicator; }
        set { Third_Party_Equals_Covered_Recipient_Indicator = value; }
    }

    public string CI
    {
        get { return Contextual_Information; }
        set { Contextual_Information = value; }
    }

    public string DIP
    {
        get { return Delay_in_Publication_Indicator; }
        set { Delay_in_Publication_Indicator = value; }
    }

    public string RI
    {
        get { return Record_ID; }
        set { Record_ID = value; }
    }

    public string DSF
    {
        get { return Dispute_Status_for_Publication; }
        set { Dispute_Status_for_Publication = value; }
    }

    public string RPI
    {
        get { return Related_Product_Indicator; }
        set { Related_Product_Indicator = value; }
    }

    public string CON1
    {
        get { return Covered_or_Noncovered_Indicator_1; }
        set { Covered_or_Noncovered_Indicator_1 = value; }
    }

    public string IDO1
    {
        get { return Indicate_Drug_or_Biological_or_Device_or_Medical_Supply_1; }
        set { Indicate_Drug_or_Biological_or_Device_or_Medical_Supply_1 = value; }
    }

    public string PCO1
    {
        get { return Product_Category_or_Therapeutic_Area_1; }
        set { Product_Category_or_Therapeutic_Area_1 = value; }
    }

    public string NOD1
    {
        get { return Name_of_Drug_or_Biological_or_Device_or_Medical_Supply_1; }
        set { Name_of_Drug_or_Biological_or_Device_or_Medical_Supply_1 = value; }
    }

    public string ADO1
    {
        get { return Associated_Drug_or_Biological_NDC_1; }
        set { Associated_Drug_or_Biological_NDC_1 = value; }
    }

    public string CON2
    {
        get { return Covered_or_Noncovered_Indicator_2; }
        set { Covered_or_Noncovered_Indicator_2 = value; }
    }

    public string IDO2
    {
        get { return Indicate_Drug_or_Biological_or_Device_or_Medical_Supply_2; }
        set { Indicate_Drug_or_Biological_or_Device_or_Medical_Supply_2 = value; }
    }

    public string PCO2
    {
        get { return Product_Category_or_Therapeutic_Area_2; }
        set { Product_Category_or_Therapeutic_Area_2 = value; }
    }

    public string NOD2
    {
        get { return Name_of_Drug_or_Biological_or_Device_or_Medical_Supply_2; }
        set { Name_of_Drug_or_Biological_or_Device_or_Medical_Supply_2 = value; }
    }

    public string ADO2
    {
        get { return Associated_Drug_or_Biological_NDC_2; }
        set { Associated_Drug_or_Biological_NDC_2 = value; }
    }

    public string CON3
    {
        get { return Covered_or_Noncovered_Indicator_3; }
        set { Covered_or_Noncovered_Indicator_3 = value; }
    }

    public string IDO3
    {
        get { return Indicate_Drug_or_Biological_or_Device_or_Medical_Supply_3; }
        set { Indicate_Drug_or_Biological_or_Device_or_Medical_Supply_3 = value; }
    }

    public string PCO3
    {
        get { return Product_Category_or_Therapeutic_Area_3; }
        set { Product_Category_or_Therapeutic_Area_3 = value; }
    }

    public string NOD3
    {
        get { return Name_of_Drug_or_Biological_or_Device_or_Medical_Supply_3; }
        set { Name_of_Drug_or_Biological_or_Device_or_Medical_Supply_3 = value; }
    }

    public string ADO3
    {
        get { return Associated_Drug_or_Biological_NDC_3; }
        set { Associated_Drug_or_Biological_NDC_3 = value; }
    }

    public string CON4
    {
        get { return Covered_or_Noncovered_Indicator_4; }
        set { Covered_or_Noncovered_Indicator_4 = value; }
    }

    public string IDO4
    {
        get { return Indicate_Drug_or_Biological_or_Device_or_Medical_Supply_4; }
        set { Indicate_Drug_or_Biological_or_Device_or_Medical_Supply_4 = value; }
    }

    public string PCO4
    {
        get { return Product_Category_or_Therapeutic_Area_4; }
        set { Product_Category_or_Therapeutic_Area_4 = value; }
    }

    public string NOD4
    {
        get { return Name_of_Drug_or_Biological_or_Device_or_Medical_Supply_4; }
        set { Name_of_Drug_or_Biological_or_Device_or_Medical_Supply_4 = value; }
    }

    public string ADO4
    {
        get { return Associated_Drug_or_Biological_NDC_4; }
        set { Associated_Drug_or_Biological_NDC_4 = value; }
    }

    public string CON5
    {
        get { return Covered_or_Noncovered_Indicator_5; }
        set { Covered_or_Noncovered_Indicator_5 = value; }
    }

    public string IDO5
    {
        get { return Indicate_Drug_or_Biological_or_Device_or_Medical_Supply_5; }
        set { Indicate_Drug_or_Biological_or_Device_or_Medical_Supply_5 = value; }
    }

    public string PCO5
    {
        get { return Product_Category_or_Therapeutic_Area_5; }
        set { Product_Category_or_Therapeutic_Area_5 = value; }
    }

    public string NOD5
    {
        get { return Name_of_Drug_or_Biological_or_Device_or_Medical_Supply_5; }
        set { Name_of_Drug_or_Biological_or_Device_or_Medical_Supply_5 = value; }
    }

    public string ADO5
    {
        get { return Associated_Drug_or_Biological_NDC_5; }
        set { Associated_Drug_or_Biological_NDC_5 = value; }
    }

    public string PY
    {
        get { return Program_Year; }
        set { Program_Year = value; }
    }

    public string PPD
    {
        get { return Payment_Publication_Date; }
        set { Payment_Publication_Date = value; }
    }



}
#endregion

标签: c#asp.net-web-apissis

解决方案


好的,我得到了这个工作,并想和你一起做一些事情。

首先,为什么您会收到错误消息“无法将属性或索引器“Output0Buffer.ChangeType”分配给——它是只读的”。您得到这个的原因是您将输出 0 缓冲区上的每个属性都设置为“文本流 [DT_TEXT]”。这是一种 blob 数据类型,相当于 SQL Server 中的 varchar(max) 或 Text,不能简单地使用“=”进行分配。为了在代码中执行此操作,您必须执行此操作(Change_Type 的示例):

if (py.change_type != null)
                    {
                        Output0Buffer.ChangeType.AddBlobData(Encoding.ASCII.GetBytes(py.change_type));
                    }
                    else
                    {
                        Output0Buffer.ChangeType.SetNull();
                    }

您应该注意编码。我将其默认为 ASCII,但如果您打算在其中看到国际字符,则应将其更改为 Unicode。

其次,仅对所有内容都使用 varchar(max) 并为每个属性分配其真实数据类型和长度并不是一个好习惯。对于字符串,对 unicode 数据使用“string [DT_STR]”或“Unicode string [DT_WSTR]”。如果您将此数据发送到 SQL Server,则目标数据类型应分别为 varchar 或 nvarchar。我将 change_type 作为文本留在代码中供您参考,以防万一其中任何一个确实包含大于 8000 个字符的文本。我找不到这个 JSON 的元数据,所以我对每个字段的数据类型做了最好的猜测。这将按照我在博客中的分配方式进行分配:

Output0Buffer.CoveredRecipientType = py.covered_recipient_type;

第三,我将两个日期字段 date_of_payment 和 payment_publication_date 从字符串更改为“数据库时间戳 [DT_DBTIMESTAMP]”供您参考。这将等效于 SQL Server 中的 datetime 数据类型。如果需要,您可以随时将其更改回字符串:

Output0Buffer.PaymentPublicationDate = DateTime.Parse(py.payment_publication_date);

我使用 DataContracts 完成了这个反序列化,但是你可以使用任何适合你的方法。这只是为了让您有一个工作参考来构建您的 SSIS 包。


推荐阅读