Member of the LearnItFirst.com Video Training Network | LearnSqlServer.com | SQL SSIS Training | SQL Programming Tutorials |
LearnSqlServer.com Forums LearnSqlServer.com
Welcome Guest Search | New Posts | Members | Log In | Register

Run SQL script from command line - Please help. Options
Tu
Posted: Wednesday, October 25, 2006 10:28:27 AM
Rank: Newbie

Joined: 10/25/2006
Posts: 1
Points: 9
Hi,

I've been trying this to no success and I wish for you help please...

ISSUE: There are some database maintenance jobs that I want to run from a command line. To be more specific, I have a package that imports outside data into a table (created by using the DTS tool). It also has a scheduled job to run it. Now I want to run that package from a command line.

I tried to export the job into a script file (c:\test.sql) and run the following from the command line:

OSQL -E -I c:\test.sql

but what I got from the command line is the string 1> 2> 3> and so on. If we look at the test.sql file, it contains the codes that the server generated.
If I create a simple script file that contains some simple TSQL commands then everything runs fine.

So please help show me how to run such a DB Maintenance job from the command line.

Thanks alot.


Tu
Scott Whigham
Posted: Wednesday, October 25, 2006 12:43:25 PM


Rank: Super Mod

Joined: 3/20/2006
Posts: 345
Points: 748
Location: Dallas, TX
As for running this from the dos prompt, you can't directly run a maintenance plan. What you do is you have to individually run the jobs that the maintenance plan creates. There is a stored procedure - sp_start_job - and you can run the job(s) that you created via the Database Maintenance Plan Wizard using it.

Hope this helps!

Scott Whigham
Tu
Posted: Thursday, October 26, 2006 6:24:14 AM
Rank: Newbie

Joined: 10/25/2006
Posts: 1
Points: 9
Wonderful! It works. Smile

I used the following command in DOS:

osql -E -i C:\test.sql

where C:\test.sql is a script file containing the following commands:

USE msdb
EXEC dbo_start_job N'TestJob'
GO

where TestJob is the job name.

Thanks so much Scott. You're my *savior* Smile

Tu
Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.
     
Don't Forget!
LearnItFirst.com
Don't Forget!
LearnSqlServe.com
 
Home | About Us | Support | Contact Us | Privacy | Site Map | Blogs Blogs Refer a Friend and Get a Free Subscription!
© Copyright 2004-2007 LearnItFirst.com LLC. All rights reserved. All trademarks remain the property of their respective owners.
This site is not affiliated in any way with the Microsoft Corporation.