-1
  • 我在一个文件夹中有 10 个平面文件(.dat 格式),需要每天在预定时间上传到数据库中。
  • 所有文件相关信息都存在于数据库中,如文件名、文件路径、表名、列名和分隔符。
  • 我们需要检查每个文件是否存在,如果不存在,需要记录一个条目,“找不到文件”。
  • 如果文件存在,则需要检查尾部记录(文件中的最后一条记录,Count=00001000,它必须是该特定文件中记录数的计数)。
  • 如果拖车记录不存在,则需要记录“未找到拖车记录”条目。如果拖车记录显示零计数,则必须将日志条目设为“零计数”,并且如果文件的计数为需要不匹配的日志条目,“计数不匹配”。
  • 如果满足所有条件,则需要将每个文件的数据加载到数据库中。

请提出您实施上述方案的想法。谢谢!!!

4

1 回答 1

1

以下解决方案可能会帮助您解决问题。

将 For each 循环容器与"Item" enumerator. 由于您有 10 个文件,如果缺少某些文件需要 raise,那么您应该使用它。文件枚举器只是遍历文件,不会引发任何错误。

以下是步骤。

使用变量创建以下 SSIS 包。

  1. 文件全路径
  2. 已验证

对于每个循环枚举器应配置为以下屏幕截图。

集合中的配置: 在此处输入图像描述

变量部分中的配置 在此处输入图像描述

容器内部有一个脚本任务。您必须提及FileFullPathas readonly 变量和IsValidateread and write ,如下面的屏幕所示。

在此处输入图像描述

单击编辑脚本并插入以下代码。

public void Main()
{
        Dts.Variables["IsValidated"].Value = true;

        string fileFullPath = Dts.Variables["FileFullPath"].Value.ToString();

            if (!File.Exists(fileFullPath))
            {
                    var msg = String.Format("File is not available in location : {0}", fileFullPath);
                    Dts.Events.FireError(0, "Dat file loading", msg, string.Empty, 0);
                    Dts.TaskResult = (int)ScriptResults.Failure;
            }

            //Read last line
            String lstLine = File.ReadLines(fileFullPath).Last();

            int totalCount = 0;
            bool talierExists = int.TryParse(lstLine, out totalCount);

            if (!talierExists)
            {
                    var msg = String.Format("No tailer row found and last line is : {0}", lstLine);
                    Dts.Events.FireError(0, "Dat file loading", msg, string.Empty, 0);
                    Dts.TaskResult = (int)ScriptResults.Failure;
            }

            //Total count
            int fullCount = File.ReadLines(fileFullPath).Count();

            if (fullCount != totalCount)
            {
                    var msg = String.Format("No of count is not matching, tailer count = {0} and full count={1}");
                    Dts.Events.FireError(0, "Dat file loading", msg, string.Empty, 0);
                    Dts.TaskResult = (int)ScriptResults.Failure;
            }

            Dts.Variables["IsValidated"].Value = true;

            Dts.TaskResult = (int)ScriptResults.Success;
}

之后有你的数据流。将脚本任务与您的数据流连接,然后右键单击连接器并进行如下编辑和配置。

在此处输入图像描述

您的 SSIS 包将如下所示。

在此处输入图像描述

希望这可以帮助!

于 2013-07-11T06:43:11.280 回答