繁体   English   中英

SSIS脚本任务问题

[英]SSIS script task issue

使用Visual Studio 2013的SSDT,可以使用SmtpClient类通过ssis脚本发送电子邮件通知。

        public void Main()
    {
        SmtpClient v_EmailClient;
        string v_From = Dts.Variables["User::vFrom"].Value.ToString();
        string v_To = Dts.Variables["User::vTo"].Value.ToString();
        string v_EnvNameToSubject = Dts.Variables["User::vEnvNameToSubject"].Value.ToString();

        MailMessage v_EmailMessage = new MailMessage(v_From, v_To);
        v_EmailMessage.IsBodyHtml = true;
        v_EmailMessage.Subject = v_EnvNameToSubject + "SSIS email notification"; 
        //Concatenation of variable with the standard message does not work

        v_EmailMessage.Body = "Message text";
        v_EmailClient = new SmtpClient("SmtpServer");
        v_EmailClient.UseDefaultCredentials = true;
        v_EmailClient.Send(v_EmailMessage);

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

当我尝试将变量v_EnvNameToSubject与标准主题文本连接在一起时不起作用。 我试图使用try catch块来查找实际的错误消息,但这也没有帮助。

首先 ,检查变量名称(和vFromvFromvTovEnvNameToSubject因为它们区分大小写。

其次 ,尽量串联这些字符串的另一种方式(使用String.Concat()函数或使用stringbuilder ):

System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.AppendLine(v_EnvNameToSubject);
sb.AppendLine("SSIS email notification");
v_EmailMessage.Subject = sb.ToString();

要么

v_EmailMessage.Subject = String.Concat(v_EnvNameToSubject,"SSIS email notification")

第三 ,检查您的变量范围,并将其添加到脚本任务“ ReadOnly Variables

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM