2014-03-03 25 views
0

我放置了一個腳本任務,其中包含將電子郵件On Error發送到Event Handler的代碼。現在我需要附加或發送輸出或錯誤日誌與消息。如何將輸出或錯誤附加到SSIS事件處理程序中的電子郵件腳本

我已經搜索並找不到明確的解決方案。

注意:郵件驗證是一個包含驗證信息的類。

電子郵件代碼:

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

public static string EmailBody() 
{ 
StringBuilder userMessage = new StringBuilder(); 
userMessage.Append("Mail Body Text"); 
userMessage.Append("Mail Body Text"); 

userMessage.Append("\n\nMail Body Text"); 
userMessage.Append("\nMail Body Text"); 
userMessage.Append("\nMail Body Text"); 

return userMessage.ToString(); 
} 

public void Main() 
{ 
var fromAddress = new MailAddress(MailAuthentication.mailFrom, "From Me"); 
var toAddress = new MailAddress(MailAuthentication.mailTo, "To Someone"); 
const string fromPassword = MailAuthentication.password; 
const string subject = "Who Shot the couch"; 

string body = EmailBody().ToString(); 

var smtp = new SmtpClient 
{ 
Host = MailAuthentication.liveSMTP, 
Port = 587, 
EnableSsl = true, 
DeliveryMethod = SmtpDeliveryMethod.Network, 
Credentials = new NetworkCredential(fromAddress.Address, fromPassword), 
Timeout = 20000 
}; 
using (var message = new MailMessage(fromAddress, toAddress) 
{ 
Subject = subject, 
Body = body 
}) 
{ 
smtp.Send(message); 
} 
} 

enum ScriptResults 
{ 
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success, 
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure 
}; 

} 

回答

0

我的建議是配置包的日誌文件中寫入錯誤日誌(example)。然後創建一個關於此錯誤的軟件包,錯誤時使用電子郵件任務或腳本發送文件。

Here是一種可能的解決方案。

相關問題