问题描述
我需要每天导入一个平面文件.该文件每天都在更改其名称.处理完文件后,需要将其移动到另一个文件夹.
I need to import a flat file daily. The file changes its name every day. After the file is processed, it needs to be moved to another folder.
我注意到我可以在 SQL Server 代理中安排作业,并且我可以告诉它每隔一小时左右运行一次,并且我可以向它添加 CMD 命令.
I noticed I can schedule jobs in the SQL Server Agent, and that I can tell it to run every hour or so and that I am able to add CMD commands to it.
我找到的解决方案是运行一个脚本来检查文件是否存在,因为文件夹应该是空的或者至少有一个文件.
The solution I found was to run a script to check if the file exists, since the folder should be empty or have at least one file.
如果文件存在,脚本会将文件重命名为 SSIS 包中使用的文件,然后运行 SSIS 包.
If the file exists, the script renames the file to one used in the SSIS package and then it runs the SSIS package.
整个事情完成后,它应该根据今天的日期再次重命名文件并将其移动到另一个文件夹.
After the whole thing is done, it should rename the file again based on today's date and move it to another folder.
如果文件不存在,那么它应该什么都不做,再等一个小时左右再次运行.
If the file does not exist, then it should do nothing and wait another hour or so to run again.
这种情况的最佳解决方案是什么?剧本是个好主意吗?也许可以将 if/else -对于文件存在 - 添加到 SSIS 包中?或者甚至让脚本从 SSIS 包本身运行,而不是将它添加到服务器代理?
What's the best solution to this scenario? Is the script a good idea? Maybe is it possible to add the if/else -for the file exists- into the SSIS package? Or even make the script run from the SSIS package itself instead of adding it to the Server Agent?
看来我有点天真了,可以从服务器运行 VB 脚本.那会是推荐的解决方案吗?它确实解决了我的问题,但我只是想知道这是否是个好主意.
It seems I was a little naïve, it's possible to run VB scripts from the server. Would that be the recommended solution? It does solve my problem, but I'm just wondering if it's a good idea.
推荐答案
这解决了我所有的问题:
This solves all my questions:
http://www.sqlservercentral.com/articles/Integration+服务+%28SSIS%29/90571/
这篇关于如果服务器文件夹中存在文件,我如何执行 SQL Server 代理作业?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!