如果服务器文件夹中存在文件,我该如何执行SQL Server代理作业? [英] How can I a SQL Server Agent job if a file exists in a server folder?

查看:94
本文介绍了如果服务器文件夹中存在文件,我该如何执行SQL Server代理作业?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要每天导入一个平面文件。该文件每天都会更改其名称。处理完文件后,需要将其移动到另一个文件夹。

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+Services+%28SSIS%29/ 90571 /

这篇关于如果服务器文件夹中存在文件,我该如何执行SQL Server代理作业?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆