简体   繁体   中英

SSIS script task issue

Using SSDT for Visual Studio 2013 am sending e-mail notifications via ssis script using SmtpClient class.

        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;
    }

When I try to concatenate the variable v_EnvNameToSubject with the standard subject text does not work. I tried to use try catch block to find out the actual error message and that did not help either.

First , check your variables names (and cases) vFrom , vTo , vEnvNameToSubject because they are case sensitive.

Second , Try concatenating these strings another way (Using String.Concat() Function or using a stringbuilder ) :

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

Or

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

Third , Check your variables scope and that they are added to the script task ReadOnly Variables

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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