[英]SSIS script task issue
Using SSDT for Visual Studio 2013 am sending e-mail notifications via ssis script using SmtpClient class. 使用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;
}
When I try to concatenate the variable v_EnvNameToSubject with the standard subject text does not work. 当我尝试将变量v_EnvNameToSubject与标准主题文本连接在一起时不起作用。 I tried to use try catch block to find out the actual error message and that did not help either. 我试图使用try catch块来查找实际的错误消息,但这也没有帮助。
First , check your variables names (and cases) vFrom
, vTo
, vEnvNameToSubject
because they are case sensitive. 首先 ,检查变量名称(和vFrom
) vFrom
, vTo
, vEnvNameToSubject
因为它们区分大小写。
Second , Try concatenating these strings another way (Using String.Concat()
Function or using a stringbuilder
) : 其次 ,尽量串联这些字符串的另一种方式(使用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();
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
第三 ,检查您的变量范围,并将其添加到脚本任务“ ReadOnly Variables
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.