home
training courses
why choose us?
solutions
support
company
LearnItFirst User Forum
Welcome Guest
Search
|
New Posts
|
Members
|
Log In
|
Register
SQL Server Forum - LearnItFirst.com
»
SQL Server Database Administration
»
Backup, Recovery and Disaster Recovery
»
Run SQL script from command line - Please help.
Run SQL script from command line - Please help.
Options
Previous Topic
·
Next Topic
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
Back to top
Scott Whigham
Posted:
Wednesday, October 25, 2006 12:43:25 PM
Rank: Super Mod
Joined: 3/20/2006
Posts: 466
Points: 1,020
Where do you live?: 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
Back to top
Tu
Posted:
Thursday, October 26, 2006 6:24:14 AM
Rank: Newbie
Joined: 10/25/2006
Posts: 1
Points: 9
Wonderful! It works.
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*
Tu
Back to top
Users browsing this topic
Guest
Forum Jump
SQL Server Database Administration
- General SQL Database Question & Answer
- Backup, Recovery and Disaster Recovery
- SQL Server Security
- Integration Services (SSIS) and DTS
Transact-SQL Programming
- DML (SELECT, INSERT, UPDATE, DELETE) Questions
- Stored Procedures, Triggers, & Functions
SQL Server Scripts, Code Samples and SSMS Custom Reports
- All SQL Server Versions
- SQL Server 2005/2008
- SQL Server Management Studio Custom Reports
Customer Service
- Video Requests
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.
SQL Server 2005 DBA Training Videos
SQL Server 2008 DBA Training Videos
Email this topic
RSS Feed
Watch this topic
Print this topic
Normal
Threaded