Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 如果发送邮件失败,请多次尝试执行发送邮件任务_Sql Server_Ssis_Ssis 2012 - Fatal编程技术网

Sql server 如果发送邮件失败,请多次尝试执行发送邮件任务

Sql server 如果发送邮件失败,请多次尝试执行发送邮件任务,sql-server,ssis,ssis-2012,Sql Server,Ssis,Ssis 2012,我在包中实现了一个发送邮件任务,它在成功或失败时发送邮件通知。由于以下错误,发送邮件任务有时会失败 Task failed: Send Mail Task with Success Error Code: -1073548540 ErrorMessage: An error occurred with the following error message: "Failure sending mail. System.IO.IOException: Unable to read data fr

我在包中实现了一个发送邮件任务,它在成功或失败时发送邮件通知。由于以下错误,发送邮件任务有时会失败

Task failed: Send Mail Task with Success
Error Code: -1073548540
ErrorMessage: An error occurred with the following error message: "Failure sending mail. 
System.IO.IOException: Unable to read data from the transport connection: 
An existing connection was forcibly closed by the remote host.  
System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host"
我已经向网络管理员报告了这个问题,但他们建议如下

The errors you are receiving from Mailhub can happen occasionally when trying to open a connection.  
The only way to resolve this issue is to force multiple retries.  If you can, please try to code in ~3-4 retries in your app.
我相信这可以通过脚本任务来完成。我不确定是否可以在使用“发送邮件”任务失败时执行多次尝试

我已经用发送邮件任务实现了20多个包。我尝试以最小的变化实现这种方法

我尝试了SQL Server代理作业步骤配置,用户可以选择配置重试尝试和重试间隔,但失败时会运行整个包,这不适合我的场景。
我必须单独运行“仅发送邮件”任务,以防多次尝试都无法发送邮件。

以避免对项目进行太多修改

使用for容器创建一个新包,您可以在其中控制重复次数。
创建int类型的变量。
添加包执行任务。
如果执行正确,请为中断for循环的变量赋值。
若出现错误,您可以在数据库或任何您想要的地方注册它

下图适用于ssis-2008,但与ssis-2012相同

您提到了C#选项:

以下是您正在寻找的逻辑:

int retryCount = 0;

retry:

try
{
     [Build and send your email]
}
catch
{
     retryCount++;
     if(retryCount<4) goto retry; //will try 4 times no matter what caused it to fall in to the catch
}
int retryCount=0;
重试:
尝试
{
[构建并发送您的电子邮件]
}
抓住
{
retryCount++;

如果(RetryCount我有一个单独的send mail包,我可以在脚本任务中处理所有问题。该包接受从父级传递的参数,包括收件人、正文、附件等。因此,任何包都可以调用该包并只发送适当的参数。我发现这种方法比使用许多SendMail对象要好。感谢您的建议我试过用do-while循环,不过我选择了你的答案。