问题描述
我有一个非常简单的ssis任务,当前它只是一个平面文件连接和一个用于更新表的批量插入任务。在继续批量插入之前,我不知道如何确保平面文件已经创建。
解决方法
在“数据流”块中,添加一个脚本组件,如下所示:
接下来,按如下所示配置脚本:
现在,您可以在脚本组件和数据流块之间的箭头上添加以下表达式:
您在脚本本身中的代码将是:
public void Main()
{
string fileName = Dts.Variables["FileName"].Value.ToString();
FileInfo fi = new FileInfo(fileName);
Dts.Variables["FileWasCreatedToday"].Value = fi.CreationTime >= DateTime.Now.Date;
// Another option would be to set this to fail if it's not created today. This will fail the whole package.
Dts.TaskResult = (int)ScriptResults.Success;
}
编辑:如果您希望它在发生故障的情况下向您发送电子邮件,只需使用以下表达式创建从脚本任务到发送邮件任务的第二个链接:{{1 }}。如下所示: