【发布时间】:2018-03-26 01:07:23
【问题描述】:
我正在尝试使用 SSIS 在电子邮件中发送一组查询结果。以下是流程的屏幕截图和步骤。
截图:
步骤: 1.使用SQL任务获取“queryresult”对象变量中的查询结果 2.在Foreach循环中使用“queryresult”对象变量,获取字符串变量“ProjectRefID”和“Accountnumber”中的列Values
3.使用foreachloop容器内的脚本任务来捕获对象变量“查询结果”中的数据
-
以下是我从网上复制的脚本任务中的代码。
使用系统; 使用 System.Data; 使用 Microsoft.SqlServer.Dts.Runtime; 使用 System.Windows.Forms;
结束区域
namespace ST_77e6b4ea18824b909adc5568475fcf5c { [Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute] public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase { public void Main() { Variables varCollection = null; string header = string.Empty; string message = string.Empty; Dts.VariableDispenser.LockForWrite("User::ValidationEmailMessage"); Dts.VariableDispenser.LockForRead("User::Accountnumber"); Dts.VariableDispenser.LockForRead("User::ProjectRefID"); Dts.VariableDispenser.GetVariables(ref varCollection); if (varCollection["User::ValidationEmailMessage"].Value == string.Empty) { header = "Below are the list of Invalid ProjecRefID and Accountnumbers that are not matching with our existing data:\n\n"; header += string.Format("{0}\t{1}\t\t\t{2}\n", "ProjectRefID", "Accountnumber"); varCollection["User::ValidationEmailMessage"].Value = header; varCollection.Unlock(); } //Format the query result with tab delimiters message = string.Format("{0}\t{1}\t{2}", varCollection["User::ProjectRefID"].Value, varCollection["User::Accountnumber"].Value); varCollection["User::ValidationEmailMessage"].Value = varCollection["User::ValidationEmailMessage"].Value + message; varCollection.Unlock(); Dts.TaskResult = (int)ScriptResults.Success; } enum ScriptResults { Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success, Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure }; }}
我试图解决这个错误,但不知何故我无法解决这个问题。如果有人知道如何解决,请告诉我。
【问题讨论】: