[英]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塊來查找實際的錯誤消息,但這也沒有幫助。
首先 ,檢查變量名稱(和vFrom
) vFrom
, vTo
, vEnvNameToSubject
因為它們區分大小寫。
其次 ,盡量串聯這些字符串的另一種方式(使用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.