【问题标题】:SSIS Script Task to send email doesnot show the data correctly发送电子邮件的 SSIS 脚本任务未正确显示数据
【发布时间】:2022-01-08 13:42:15
【问题描述】:

我正在尝试查询数据库并发送电子邮件正文中的内容。内容是订单和每个用户的详细信息。我正在尝试调用脚本任务来撰写正文,并且我正在使用发送电子邮件任务中的内容。当我尝试运行包时,它执行时没有错误,但低于我在电子邮件中看到的内容

Execute SQL task output sent using Send Email Task in SSIS:

Customer Num    Rec Loc Strain  StrainCode  Age Sex Genotype    Sent From   Quantity
Microsoft.SqlServer.Dts.Runtime.Variable    Microsoft.SqlServer.Dts.Runtime.Variable    Microsoft.SqlServer.Dts.Runtime.Variable    Microsoft.SqlServer.Dts.Runtime.Variable    Microsoft.SqlServer.Dts.Runtime.Variable    Microsoft.SqlServer.Dts.Runtime.Variable    Microsoft.SqlServer.Dts.Runtime.Variable    Microsoft.SqlServer.Dts.Runtime.Variable    Microsoft.SqlServer.Dts.Runtime.Variable

下面是脚本

namespace ST_c074d0acfee7488b96d42a0f858efee7
{
       [Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
        public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
        {

            #region VSTA generated code
            enum ScriptResults
            {
                Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
                Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
            };
            #endregion

            public void Main()
            {
                string header = string.Empty;
                string message = string.Empty;

                header = "Execute SQL task output sent using Send Email Task in SSIS:\n\n";
                header += string.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\n", "Customer Num", "Rec Loc", "Strain", "StrainCode", "Age", "Sex", "Genotype", "Sent From", "Quantity");
                message = string.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}",
                                            Dts.Variables["User::CustomerNumber"].ToString(),
                                            Dts.Variables["User::ReceivingLocation"].ToString(),
                                            Dts.Variables["User::StrainName"].ToString(),
                                            Dts.Variables["User::StrainCode"].ToString(),
                                            Dts.Variables["User::Age"].ToString(),
                                            Dts.Variables["User::Sex"].ToString(),
                                            Dts.Variables["User::Genotype"].ToString(),
                                            Dts.Variables["User::SentFrom"].ToString(),
                                            Dts.Variables["User::OrderQuantity"].ToString());

            Dts.Variables["User::EmailMessage"].Value= header + message;

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

下面是包

对于脚本任务属性,我将传递所有必需的数据,如下所示

以及获取所有数据的查询

我正在做映射的 For 循环

谁能告诉我我在这里缺少什么以及为什么我的电子邮件没有显示真实数据

【问题讨论】:

    标签: c# sql sql-server ssis etl


    【解决方案1】:

    我找到了我必须做的问题

     Dts.Variables["User::Age"].Value.ToString(),
    

    代替

    Dts.Variables["User::Age"].ToString(),
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-15
      • 1970-01-01
      • 1970-01-01
      • 2012-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多