以下解决方案可能会帮助您解决问题。
将 For each 循环容器与"Item" enumerator
. 由于您有 10 个文件,如果缺少某些文件需要 raise,那么您应该使用它。文件枚举器只是遍历文件,不会引发任何错误。
以下是步骤。
使用变量创建以下 SSIS 包。
- 文件全路径
- 已验证
对于每个循环枚举器应配置为以下屏幕截图。
集合中的配置:

变量部分中的配置

容器内部有一个脚本任务。您必须提及FileFullPath
as readonly 变量和IsValidate
read 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 包将如下所示。

希望这可以帮助!