2015-05-12 50 views
2

我想用一個腳本組件來執行的SSIS包的Visual Basic 2010年,我得到以下錯誤,當我執行該程序包:SSIS DTS腳本任務遇到用戶代碼的異常

enter image description here

public void Main() 
    { 
     // TODO: Custom Code starts here 
     /* 
     * Description: Reads the input CMI Stats files and converts into a more readable format 
     * This Code for Better CMI Parser is converted as per SC's original code by S.A. on 3/6/2014 
     * Here is the description from original procedure 
     * CustType = DOMESTIC/INTERNATIONAL/ETC 
     * CategoryType = SBU/MAN 
     * Category = Actual value (AI/CC/etc) 
     * DataType = INCOMING or SHIP (or something else later?) 
     * 
     * 3/23/2010 
     * Uncommented the CAD file load.... 
     */ 
     string[,] filesToProcess = new string[2, 2] { {(String)Dts.Variables["csvFileNameUSD"].Value,"USD" }, {(String)Dts.Variables["csvFileNameCAD"].Value,"CAD" } }; 
     string headline = "CustType,CategoryType,CategoryValue,DataType,Stock QTY,Stock Value,Floor QTY,Floor Value,Order Count,Currency"; 
     string outPutFile = Dts.Variables["outputFile"].Value.ToString(); 
     //Declare Output files to write to 
     FileStream sw = new System.IO.FileStream(outPutFile, System.IO.FileMode.Create); 
     StreamWriter w = new StreamWriter(sw); 
     w.WriteLine(headline); 

     //Loop Through the files one by one and write to output Files 
     for (int x = 0; x < filesToProcess.GetLength(1); x++) 
     {     
      if (System.IO.File.Exists(filesToProcess[x, 0])) 
      { 
       string categoryType = ""; 
       string custType = ""; 
       string dataType = ""; 
       string categoryValue = ""; 

       //Read the input file in memory and close after done 
       StreamReader sr = new StreamReader(filesToProcess[x, 0]); 
       string fileText = sr.ReadToEnd(); 
       string[] lines = fileText.Split(Convert.ToString(System.Environment.NewLine).ToCharArray()); 
       sr.Close();           

       //Read String line by line and write the lines with params from sub headers 
       foreach (string line in lines) 
       { 
        if (line.Split(',').Length > 3) 
        { 
         string lineWrite = ""; 
         lineWrite = line; 
         string[] cols = line.Split(','); 
         if (HeaderLine(cols[1])) 
         { 
          string[] llist = cols[0].Split(); 
          categoryType = llist[llist.Length - 1]; 
          custType = llist[0]; 
          dataType = llist[1]; 
          if (dataType == "COMPANY") 
          { 
           custType = llist[0] + " " + llist[1]; 
           dataType = llist[2]; 
          } 
         } 
         if (cols[0].Contains("GRAND")) 
         { 
          categoryValue = "Total"; 
         } 
         else 
         { 
          string[] col0 = cols[0].Split(' '); 
          categoryValue = col0[col0.Length - 1]; 
         } 
         int z = 0; 
         string[] vals = new string[cols.Length]; 
         for (int i = 1; i < cols.Length - 1; i++) 
         { 
          vals[z] = cols[i].Replace(',', ' '); 
          z++; 
         } 
         //line = ",".join([CustType, CategoryType, CategoryValue, DataType, vals[0], vals[1], vals[2], vals[3], vals[6], currency]) 
         lineWrite = clean(custType) + "," + clean(categoryType) + "," + clean(categoryValue) + "," 
            + clean(dataType) + "," + clean(vals[0]) + "," + clean(vals[1]) + "," + clean(vals[2]) 
            + "," + clean(vals[3]) + "," + clean(vals[6]) + "," + filesToProcess[x, 1]; 

         if (!HeaderLine(line)) 
         { 
          w.WriteLine(lineWrite); 
          w.Flush(); 
         } 
        } 
       } 
      } 

     } 

     w.Close(); 
     sw.Close(); 
     //Custom Code ends here 

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

    public bool HeaderLine(String line) 
    { 
     return line.Contains("Stock Qty"); 
    } 

    public string clean(string str) 
    { 
     if (str != null) 
      return Regex.Replace(str,@"[""]",""); 
      //return str.Replace('"', ' '); 
     else 
      return ""; 
    } 

    #region ScriptResults declaration 
    /// <summary> 
    /// This enum provides a convenient shorthand within the scope of this class for setting the 
    /// result of the script. 
    /// 
    /// This code was generated automatically. 
    /// </summary> 
    enum ScriptResults 
    { 
     Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success, 
     Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure 
    }; 
    #endregion 

} 

}

任何人都可以提出什麼可能是可能出了問題或者可能如何以瞭解錯誤調試代碼?

謝謝!

+0

您的腳本組件不在Visual Basic中。這是在C# –

+0

道歉,我的壞,我寫急 – user2673722

回答

2

這裏是你如何在SSIS

  • 隨着代碼的開放調試腳本,將斷點
  • 關閉代碼
  • 腳本啓動時運行運行包
  • ,它將開放一個代碼窗口,您可以逐步瀏覽代碼
+0

謝謝!我剛發現這是本地文件路徑的訪問問題。 – user2673722

+0

嗨,問題再次出現,我嘗試設置斷點,但我無法這樣做。還有一條小消息說在這個位置不能添加斷點 – user2673722

+0

將它添加到具有'public void main'的行上,然後你可以通過 –