SSIS 脚本组件 - 仅在调试模式下工作
Posted
技术标签:
【中文标题】SSIS 脚本组件 - 仅在调试模式下工作【英文标题】:SSIS Script Component - will only work in debug mode 【发布时间】:2014-10-17 16:24:50 【问题描述】:我有一个烦人的问题。
我有一个调用 GET REST API 的 SSIS 脚本组件(数据流中的一个以避免混淆)。现在我是一名 SSIS 人员,但我拼凑了一个 .net 脚本,并提供了一些有效的帮助,但前提是设置了断点,即使它们被禁用。
删除断点后,我会立即收到以下错误。
在 Microsoft.SqlServer.Dts.Runtime.Wrapper.IDTSVariables100.get_Item(对象索引) 在 Variables.get_AddressBookIdDownload() 在 ScriptMain.CreateNewOutputRows() 在 UserComponent.PrimeOutput(Int32 输出,Int32[] OutputIDs,PipelineBuffer[] 缓冲区,OutputNameMap OutputMap) 在 Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.PrimeOutput(Int32 输出,Int32[] outputIDs,PipelineBuffer[] 缓冲区)
为了排除故障,有人(合理地)询问 .net 代码是什么...所以我将其粘贴在下面...包括所有字段映射以防出现问题...
#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
[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
public override void PreExecute()
base.PreExecute();
public override void PostExecute()
base.PostExecute();
public override void CreateNewOutputRows()
//Get SSIS Variables
string apiUserName = Variables.APIUsername;
string apiPassword = Variables.APIPassword;
int campaignId = (int) Variables.Campaign;
//Set Webservice URL
string wUrl = "https://api.aaaaaaaa.com/" + String.Concat(campaignId, "/summary");
String base64 = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(apiUserName + ":" + apiPassword));
try
//Call getWebServiceResult to return our WorkGroupMetric array
RootObject[] outPutMetrics = GetWebServiceResult(wUrl, base64 );
//For each group of metrics output records
//these are the column names defined in output columns in object
foreach (var metric in outPutMetrics)
Output0Buffer.AddRow();
Output0Buffer.dateSent = (metric.dateSent);
Output0Buffer.numUniqueOpens = metric.numUniqueOpens;
Output0Buffer.numUniqueTextOpens = metric.numUniqueTextOpens;
Output0Buffer.numTotalUniqueOpens = metric.numTotalUniqueOpens;
Output0Buffer.numOpens = metric.numOpens;
Output0Buffer.numTextOpens = metric.numTextOpens;
Output0Buffer.numTotalOpens = metric.numTotalOpens;
Output0Buffer.numClicks = metric.numClicks;
Output0Buffer.numTextClicks = metric.numTextClicks;
Output0Buffer.numTotalClicks = metric.numTotalClicks;
Output0Buffer.numPageViews = metric.numPageViews;
Output0Buffer.numTotalPageViews = metric.numTotalPageViews;
Output0Buffer.numTextPageViews = metric.numTextPageViews;
Output0Buffer.numForwards = metric.numForwards;
Output0Buffer.numTextForwards = metric.numTextForwards;
Output0Buffer.numEstimatedForwards = metric.numEstimatedForwards;
Output0Buffer.numTextEstimatedForwards = metric.numTextEstimatedForwards;
Output0Buffer.numTotalEstimatedForwards = metric.numTotalEstimatedForwards;
Output0Buffer.numReplies = metric.numReplies;
Output0Buffer.numTextReplies = metric.numTextReplies;
Output0Buffer.numTotalReplies = metric.numTotalReplies;
Output0Buffer.numHardBounces = metric.numHardBounces;
Output0Buffer.numTextHardBounces = metric.numTextHardBounces;
Output0Buffer.numTotalHardBounces = metric.numTotalHardBounces;
Output0Buffer.numSoftBounces = metric.numSoftBounces;
Output0Buffer.numTextSoftBounces = metric.numTextSoftBounces;
Output0Buffer.numTotalSoftBounces = metric.numTotalSoftBounces;
Output0Buffer.numUnsubscribes = metric.numUnsubscribes;
Output0Buffer.numTextUnsubscribes = metric.numTextUnsubscribes;
Output0Buffer.numTotalUnsubscribes = metric.numTotalUnsubscribes;
Output0Buffer.numIspComplaints = metric.numIspComplaints;
Output0Buffer.numTextIspComplaints = metric.numTextIspComplaints;
Output0Buffer.numTotalIspComplaints = metric.numTotalIspComplaints;
Output0Buffer.numMailBlocks = metric.numMailBlocks;
Output0Buffer.numTextMailBlocks = metric.numTextMailBlocks;
Output0Buffer.numTotalMailBlocks = metric.numTotalMailBlocks;
Output0Buffer.numSent = metric.numSent;
Output0Buffer.numTextSent = metric.numTextSent;
Output0Buffer.numTotalSent = metric.numTotalSent;
Output0Buffer.numRecipientsClicked = metric.numRecipientsClicked;
Output0Buffer.numDelivered = metric.numDelivered;
Output0Buffer.numTextDelivered = metric.numTextDelivered;
Output0Buffer.numTotalDelivered = metric.numTotalDelivered;
Output0Buffer.percentageDelivered = metric.percentageDelivered;
Output0Buffer.percentageUniqueOpens = metric.percentageUniqueOpens;
Output0Buffer.percentageOpens = metric.percentageOpens;
Output0Buffer.percentageUnsubscribes = metric.percentageUnsubscribes;
Output0Buffer.percentageReplies = metric.percentageReplies;
Output0Buffer.percentageHardBounces = metric.percentageHardBounces;
Output0Buffer.percentageSoftBounces = metric.percentageSoftBounces;
Output0Buffer.percentageUsersClicked = metric.percentageUsersClicked;
Output0Buffer.percentageClicksToOpens = metric.percentageClicksToOpens ;
catch (Exception e)
//FailComponent(e.ToString());
if (e.Message != null)
string ExceptionMessage = e.Message;
/// <returns>An array of WorkGroupMetric composed of the de-serialized JSON</returns>
private RootObject[] GetWebServiceResult(string wUrl, string base64)
HttpWebRequest httpWReq = (HttpWebRequest)WebRequest.Create(wUrl);
httpWReq.Headers.Add("Authorization", "Basic " + base64);
HttpWebResponse httpWResp = (HttpWebResponse)httpWReq.GetResponse();
RootObject[] jsonResponse = null;
try
//Test the connection
if (httpWResp.StatusCode == HttpStatusCode.OK)
Stream responseStream = httpWResp.GetResponseStream();
dataLength = httpWResp.ContentLength;
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();
jsonResponse = sr.Deserialize<RootObject[]>(jsonString);
//Output connection error message
else
FailComponent(httpWResp.StatusCode.ToString());
//Output JSON parsing error
catch (Exception ex)
if (ex.Message != null)
string ExceptionMessage = ex.Message;
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
public class RootObject
public DateTime dateSent get; set;
public int numUniqueOpens get; set;
public int numUniqueTextOpens get; set;
public int numTotalUniqueOpens get; set;
public int numOpens get; set;
public int numTextOpens get; set;
public int numTotalOpens get; set;
public int numClicks get; set;
public int numTextClicks get; set;
public int numTotalClicks get; set;
public int numPageViews get; set;
public int numTotalPageViews get; set;
public int numTextPageViews get; set;
public int numForwards get; set;
public int numTextForwards get; set;
public int numEstimatedForwards get; set;
public int numTextEstimatedForwards get; set;
public int numTotalEstimatedForwards get; set;
public int numReplies get; set;
public int numTextReplies get; set;
public int numTotalReplies get; set;
public int numHardBounces get; set;
public int numTextHardBounces get; set;
public int numTotalHardBounces get; set;
public int numSoftBounces get; set;
public int numTextSoftBounces get; set;
public int numTotalSoftBounces get; set;
public int numUnsubscribes get; set;
public int numTextUnsubscribes get; set;
public int numTotalUnsubscribes get; set;
public int numIspComplaints get; set;
public int numTextIspComplaints get; set;
public int numTotalIspComplaints get; set;
public int numMailBlocks get; set;
public int numTextMailBlocks get; set;
public int numTotalMailBlocks get; set;
public int numSent get; set;
public int numTextSent get; set;
public int numTotalSent get; set;
public int numRecipientsClicked get; set;
public int numDelivered get; set;
public int numTextDelivered get; set;
public int numTotalDelivered get; set;
public double percentageDelivered get; set;
public double percentageUniqueOpens get; set;
public double percentageOpens get; set;
public double percentageUnsubscribes get; set;
public double percentageReplies get; set;
public double percentageHardBounces get; set;
public double percentageSoftBounces get; set;
public double percentageUsersClicked get; set;
public double percentageClicksToOpens get; set;
#endregion
有什么想法吗?
【问题讨论】:
没有看到代码,这很难解决 我怀疑你的代码有问题。 【参考方案1】:一位同事恼火地查看了脚本,发现他可以看到并没有任何问题,因此在横向思考的时刻,他创建了一个新的脚本组件并将 c# 脚本粘贴,在创建接口之后,它工作了!
不确定,但也许是脚本开发留下的一些工件导致了问题?
【讨论】:
多么愚蠢的错误,尽管我很高兴其他人发现了这个并发布了它。今天解决了我的问题。 @Marcus D:非常感谢。你拯救了我的一天。它对我有用。 这是一个......为什么答案总是应付并粘贴到新对象中? 这样,可能是SSIS/.net的实现不是很整洁以上是关于SSIS 脚本组件 - 仅在调试模式下工作的主要内容,如果未能解决你的问题,请参考以下文章
OpenGL 程序仅在 Visual Studio 2013 中的调试模式下工作
父 NSManagedObjectContext 在子保存后没有变化,但仅在发布模式下(在调试模式下工作)