在SQL Server 2008中运行批处理文件 [英] Running batch file in SQL Server 2008

查看:183
本文介绍了在SQL Server 2008中运行批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在SQL Server 2008中执行批处理文件时遇到一些问题。

我创建了一个作业,我想使用7zip压缩文件,然后将该zip文件移动到FTP服务器。我有一个批处理文件为我做这个,但我想在一份工作中运行它。



首先我创建一个工作,然后我创建一个步骤。步骤的类型转到操作系统(CmdExec)。它作为SQL Server代理服务帐户运行(管理员,与我的登录名相同)。然后在命令框中我输入了我的命令文字。



它很有效,除了没有任何反应......所以它出错了,但它没有给我一个例外。



当我直接从资源管理器运行我的批处理文件时,一切正常。如果我设置我的工作来执行以下操作:

cmd.exe / cMyFile.cmd

一切顺利。



为什么我不能把我文件的内容放在我的步骤中的命令框中并执行它(毕竟,这也是我从那个窗口打开文件时的作用)?

谢谢。

解决方案

请阅读我对这个问题的评论。



据我所知,您正在尝试从SQL作业代理运行批处理文件到zip文件并将其存档到ftp服务器上..请按照以下链接:

如何:创建CmdExec作业步骤(SQL Server Management Studio)

如何使用SQL代理作业中的CmdExec步骤运行多个操作系统命令


仅通过sql代理工作拉链

请参阅链接:

http://searchsqlserver.techtarget.com/tip/ZIP-files-with-a-stored-过程


我通过创建一个cmd文件并从我的工作中调用它来解决这个问题:MyFile.cmd。

我添加了一些参数:MyFile.cmd param1 param2......

不是我的想法,但仍然像魅力一样。


I'm having a little problem executing a batch file in SQL Server 2008.
I've created a job and I want to zip a file using 7zip and then move that zip to an FTP server. I have a batch file to do this for me, but I want to run it in a job.

So first I create a job and then I create a step. The type of the step goes to Operating System (CmdExec). It runs as the SQL Server Agent Service Account (which is admin, same as my login). And then in the Command box I put my command text.

And it works great, except that nothing happens... So it's going wrong, but it's not giving me an exception.

When I run my batch file directly from explorer everything works fine. If I set up my job to do the following:
cmd.exe /c "MyFile.cmd"
everything goes fine.

Why can't I just put the contents of my file inside the Command box in my step and execute it (after all, that's what it does when I Open a file from that window too)?
Thanks.

解决方案

Please, read my comment to the question.

As per i understand you're trying to run batch file from SQL Job Agent to zip files and put it an archive file onto ftp server.. Please, follow below links:
How to: Create a CmdExec Job Step (SQL Server Management Studio)
How to run multiple Operating System commands using CmdExec step in SQL Agent jobs


do zip by sql agent job only
see link:
http://searchsqlserver.techtarget.com/tip/ZIP-files-with-a-stored-procedure


I've gone around the problem by creating a cmd file and calling it from my job like: "MyFile.cmd".
I've added some parameters too: "MyFile.cmd param1 param2"...
Not quite what I had in mind, but works like a charm nonetheless.


这篇关于在SQL Server 2008中运行批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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