C# 如何从 sql 代理或作业执行 exe 文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11754001/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 19:06:07  来源:igfitidea点击:

How execute exe file from sql agent or job?

c#sqlsql-agent-job

提问by user1531248

I don't want to hit the database frequently based on page request, so I planned to create a xml file using separate C# coding [exe file] & put in the common path to access from different page/project, which will do the hitting stuff's daily morning, so can you explain how do I execute exe file from sql job or agent by scheduled manner?

我不想根据页面请求频繁访问数据库,所以我计划使用单独的 C# 编码 [exe 文件] 创建一个 xml 文件并放入从不同页面/项目访问的公共路径,这将执行命中东西每天早上,所以你能解释一下我如何通过预定的方式从 sql 作业或代理执行 exe 文件吗?

My scenario: database table will be updated only once, so I am going for a XML/txt file.

我的场景:数据库表只会更新一次,所以我要一个 XML/txt 文件。

Thanks, S.Venkatesh

谢谢,S.Venkatesh

回答by VoonArt

If you must do it in JOB: xp_cmdshellxp_cmdshell execute as nonadmin!

如果必须在 JOB 中 执行:xp_cmdshellxp_cmdshell 作为非管理员执行!

DECLARE @command varchar(8000)
SET @command = 'C:\MyProgram' 
EXEC master..xp_cmdshell @command

But you should shedule task in windows.

但是你应该在 Windows 中处理任务。

回答by Alberto De Caro

Executable and batch files may be added to a job as step (MSDN Implement Jobs).

可执行文件和批处理文件可以作为步骤添加到作业中(MSDN 实施作业)。

  1. Create a job
  2. Add a new step

    2.1 set "Operating system(CmdExec)" as type

    2.2 set the executable path

  1. 创建工作
  2. 添加新步骤

    2.1 设置“操作系统(CmdExec)”为类型

    2.2 设置可执行路径

enter image description here

enter image description here