ssis平面文件创建日期

时间:2020-11-04 08:54:17

标签: sql-server ssis

我有一个非常简单的ssis任务,当前它只是一个平面文件连接和一个用于更新表的批量插入任务。在继续批量插入之前,我不知道如何确保平面文件已经创建。

1 个答案:

答案 0 :(得分:0)

在“数据流”块中,添加一个脚本组件,如下所示:

enter image description here

添加两个变量,一个用于文件名,另一个用于脚本结果: enter image description here

接下来,按如下所示配置脚本:

enter image description here

现在,您可以在脚本组件和数据流块之间的箭头上添加以下表达式:

enter image description here

您在脚本本身中的代码将是:

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 }}。如下所示:

enter image description here