473,395 Members | 2,006 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

SQLAgent 2005 SP1 failed to run .bat file.

Following is our test steps.
1. Create directory E:\firefly in E:.
2. Create a test file a.txt in E:\firefly.
3. Create E:\firefly\test.bat file with the following commands:
cd E:\firefly
copy a.txt b.txt
4. Create a new job in SQL Server Management Studio with only one
step, this only step's command
type is set to "Operating system(CmdExec)", and click the "Open"
button to choose E:\firefly\test.bat
file, then the commands in test.bat are copyed to the command editor.
5. Save the job and run it, Management Studio tells the job faild, but
did not tell an error message.

If I only use the following command :copy E:\firefl\a.txt E\firefly
\b.txt, and SQLAgent can
run the command successfully via the job.

The real functionality of our job is to backup database to a file,
then use our source control tool's
command line tool to submit the backup file to the server.

Mar 26 '07 #1
5 7731
Amber (gu**********@gmail.com) writes:
Following is our test steps.
1. Create directory E:\firefly in E:.
2. Create a test file a.txt in E:\firefly.
3. Create E:\firefly\test.bat file with the following commands:
cd E:\firefly
copy a.txt b.txt
Where is SQL Server installed? If it's installed on C:, the CD command
which change the default directory on the E drive, but it will not
change the drive. You need to add this line to the file:

E:
5. Save the job and run it, Management Studio tells the job faild, but
did not tell an error message.
Find the job under SQL Server Agent, right-click and select View History.
For each job execution there is a cross, click on this to expand the
job steps. The read the output for the individual steps.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Mar 26 '07 #2
Thanks a lot, but it still fails, my test job's ddl script is as
following:

USE [msdb]
GO
/****** Object: Job [Test] Script Date: 03/27/2007 09:03:48
******/
BEGIN TRANSACTION
DECLARE @ReturnCode INT
SELECT @ReturnCode = 0
/****** Object: JobCategory [[Uncategorized (Local)]]] Script
Date: 03/27/2007 09:03:48 ******/
IF NOT EXISTS (SELECT name FROM msdb.dbo.syscategories WHERE
name=N'[Uncategorized (Local)]' AND category_class=1)
BEGIN
EXEC @ReturnCode = msdb.dbo.sp_add_category @class=N'JOB',
@type=N'LOCAL', @name=N'[Uncategorized (Local)]'
IF (@@ERROR <0 OR @ReturnCode <0) GOTO QuitWithRollback

END

DECLARE @jobId BINARY(16)
EXEC @ReturnCode = msdb.dbo.sp_add_job @job_name=N'Test',
@enabled=1,
@notify_level_eventlog=0,
@notify_level_email=0,
@notify_level_netsend=0,
@notify_level_page=0,
@delete_level=0,
@description=N'No description available.',
@category_name=N'[Uncategorized (Local)]',
@owner_login_name=N'DBS\Administrator', @job_id = @jobId OUTPUT
IF (@@ERROR <0 OR @ReturnCode <0) GOTO QuitWithRollback
/****** Object: Step [1] Script Date: 03/27/2007 09:03:48 ******/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId,
@step_name=N'1',
@step_id=1,
@cmdexec_success_code=0,
@on_success_action=1,
@on_success_step_id=0,
@on_fail_action=2,
@on_fail_step_id=0,
@retry_attempts=0,
@retry_interval=0,
@os_run_priority=0, @subsystem=N'CmdExec',
@command=N'E:
cd E:\firefly
copy a.txt b.txt',
@flags=0
IF (@@ERROR <0 OR @ReturnCode <0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_update_job @job_id = @jobId,
@start_step_id = 1
IF (@@ERROR <0 OR @ReturnCode <0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobschedule @job_id=@jobId,
@name=N'Back up Firmbank',
@enabled=1,
@freq_type=4,
@freq_interval=1,
@freq_subday_type=8,
@freq_subday_interval=1,
@freq_relative_interval=0,
@freq_recurrence_factor=0,
@active_start_date=20070305,
@active_end_date=99991231,
@active_start_time=0,
@active_end_time=235959
IF (@@ERROR <0 OR @ReturnCode <0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId,
@server_name = N'(local)'
IF (@@ERROR <0 OR @ReturnCode <0) GOTO QuitWithRollback
COMMIT TRANSACTION
GOTO EndSave
QuitWithRollback:
IF (@@TRANCOUNT 0) ROLLBACK TRANSACTION
EndSave:

And the error message is :
Executed as user: DBS\SYSTEM. The process could not be created for
step 1 of job 0x0AADA959AC29F343ADD373C3DC57A375 (reason: ¾Ü¾ø·ÃÎÊ¡£). The
step failed.
(DBS is my server's name).

Mar 27 '07 #3
And my SQL Server was installed on D:\Program Files\Microsoft SQL
Server

Mar 27 '07 #4
On 26 Mar 2007 18:11:09 -0700, "Amber" <gu**********@gmail.comwrote:
> @command=N'E:
cd E:\firefly
copy a.txt b.txt',
If these were in a bat file and you executed the bat file that should
work.

However, you are trying to execute all three commands as one, and I
believe that is the problem. You can only execute one command.

In some versions of Windows there is an option for stacking multiple
commands on a single line. I have not used it, but you might explore
using &, or &&. If that works @command would look like

@command=N'E:&cd E:\firefly&copy a.txt b.txt',

Roy Harvey
Beacon Falls, CT
Mar 27 '07 #5
I put all these command in c:\test.bat, and in SQLAgent job step I use
this OS command "C:\test.bat", it works.
Thrank you all.
Amber

Mar 28 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Darek | last post by:
Hi there; I was trying to apply SQL SP3a on my windows 2000 server (SP4), but the installation failed and when I rebooted my server the SQL agent failed to start and I get the following error:...
2
by: Maurizio Camurati | last post by:
Hi all, I have some trouble with SQLAgent...when I try to schedule a job that invokes a script (vbs, java, cmdshell,...), SQLAgent crashes at the moment of scheduled execution. If I try to execute...
2
by: DMAC | last post by:
The following failed in EM (or whatever it is called now management studio I think) and I scripted it out and ran it in a query window to get more info. This works fine in SQL 2000 but not in 2005....
0
by: Mart | last post by:
Hi, I have just written (my first) VB.net app using MS Visual Basic 2005 Express Edition Beta. It is fairly simple, it reads some configuration data from an XML file then opens a new window...
5
by: dba999 | last post by:
Hello, I have the following error message in the sqlagent.out file, looping each minute. 2005-12-19 10:58:54 - ! SQLServer Error: 14262, The specified @job_id...
10
by: WT | last post by:
Hello, I have been publishing my web site many times to the remote where resides my final web site. Everything was ok, but to-day, without any configuration change, vs doesn't copy final files...
2
by: m19peters | last post by:
We have a script that I had to rework a little bit for 2005 that does a full backup for every database on the server... For some reason on some nights the script does not backup all databases......
0
by: silviu | last post by:
Hello I'm trying to install Microsoft SQL 2005 Server Express Edition but I'm getting the following error: SQL Server Setup unexpectedly failed... Then it says something about a log file. Here's...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.