优先级约束
我创建了一个包,用于使用 FTP 任务从 FTP 提取 Excel 文件,然后将 Excel 文件处理到 SQL 数据库。从 FTP 拉取后,Excel 将存储在文件夹中。我将文件路径存储在一个变量中,并在优先级约束中给出了一个条件,以检查该文件是否存在于文件夹中。仅当文件路径存在时才执行 Excel 处理任务。但似乎即使该文件不存在,包也会执行,这会失败。所以我想检查一下我给出的条件是否错误。我在优先级约束中给出的条件如下:
@[User::FilePath] != ""
其中 @[User::FilePath] 包含文件路径,即 C:\FTPDestination\FileName.xlsx
是上述条件不正确?给出的正确条件是什么?
I have created a package to pull a excel file from FTP using FTP Task and then process the Excel file to SQL Database. After pulling from FTP, the excel will be stored in a folder. And I have stored the File path in a variable, and had given a condition in the Precedence costraint, to check whether the file exists in the folder or not. The excel processing task should be executed only if the file path exists. But it seems that even the file does not exist, the package executes, which will fail. So I wanted to check whether the condition I had given was wrong or not. The condition I had given in the precedence constraint was as follows :
@[User::FilePath] != ""
where @[User::FilePath] contains the file path ie C:\FTPDestination\FileName.xlsx
Is the above condition incorrect ? What is the correct condition to be given ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用条件
@[User::FilePath] != ""
无助于验证文件是否存在。此条件仅检查字符串变量FilePath
是否为空字符串。您可以使用以下一个选项来实现您的要求。您可以放置一个
Foreach 循环容器
来循环访问给定文件夹中的文件。配置 SSIS 包,如屏幕截图 #1 所示。放置
FTP 任务
、Foreach 循环容器
,任何任务都可以放置在 Foreach 循环容器内。创建 4 个变量,如屏幕截图 #2 所示。 FTPPath包含下载FTP文件的路径; FolderPath 包含保存文件的文件夹; FileExtension 是应匹配以在 Foreach 循环容器内循环的文件; FilePath 将是将在 Foreach 循环容器中循环的每个文件的路径。
配置
FTP 任务
,如屏幕截图 #3 和 #4 所示。配置
Foreach 循环容器
,如 scrteenshots #5 和 #6 中所示。文件从 FTP 成功下载到目标文件夹时的屏幕截图 #7。
屏幕截图 #8 显示在 FTP 文件夹中未找到匹配文件时的情况。如果您不希望 FTP 任务在找不到文件时失败,请参考我的答案 此堆栈溢出问题。
希望有帮助。
屏幕截图 #1:
屏幕截图 #2:
屏幕截图 #3:
屏幕截图 #4:
屏幕截图 #5:
屏幕截图 #6:
屏幕截图 #7:
屏幕截图 #8:< /strong>
Using the condition
@[User::FilePath] != ""
doesn't help to validate if the file exist or not. This condition will only check if the string variableFilePath
is an empty string or not.Here is a possible option that you could use to achieve your requirements. You can place a
Foreach loop container
to loop through files in a given folder.Configure the SSIS package as shown in screenshot #1. Place an
FTP task
,Foreach loop container
and any tasks can be placed inside the Foreach loop container.Create 4 variables as shown in screenshot #2. FTPPath contains the path to download the FTP files; FolderPath contains the folder to save the files to; FileExtension is the files that should be matched to loop through within the Foreach loop container; and FilePath will be the path of each file that will be looped through in Foreach loop container.
Configure the
FTP task
as shown in screenshots #3 and #4.Configure the
Foreach loop container
as shown in scrteenshots #5 and #6.Screenshot #7 when a file is successfully downloaded from FTP to the destination folder.
Screenshot #8 shows when no matching file is found in FTP folder. If you don't want the FTP task to fail when no files are found, then refer my answer in this Stack Overflow question.
Hope that helps.
Screenshot #1:
Screenshot #2:
Screenshot #3:
Screenshot #4:
Screenshot #5:
Screenshot #6:
Screenshot #7:
Screenshot #8: