Solved

execute operating system command in sql job

Posted on 2014-04-10
7
276 Views
Last Modified: 2014-04-30
Hello,

I try to execute this command in sql agent :
DECLARE @command varchar(8000)
SET @command = '"C:\Microsoft SQL Server Migration Assistant for Oracle\bin\"SSMAforOracleConsole.exe -s E:\ConversionAndDataMigration.xml -v E:\LV\VariableValueFile.xml'
EXEC master..xp_cmdshell @command

The following error is returned :
output
'C:\Microsoft' is not recognized as an internal or external command,

Why?

Thanks
0
Comment
Question by:bibi92
  • 3
7 Comments
 
LVL 20

Accepted Solution

by:
netcmh earned 300 total points
ID: 39992715
Change your strings to
'"C:\Microsoft SQL Server Migration Assistant for Oracle\bin\SSMAforOracleConsole.exe"
and
"E:\ConversionAndDataMigration.xml"
and
"E:\LV\VariableValueFile.xml"'

So, single quotes to contain everything with the double quotes to complete the paths.
0
 
LVL 20

Expert Comment

by:netcmh
ID: 39992716
Our IPS is catching the entirety of the command as a malicious attempt. Sorry :)
0
 
LVL 26

Assisted Solution

by:Zberteoc
Zberteoc earned 200 total points
ID: 39992884
Use this:
DECLARE 
	@command varchar(8000)
-- create a temp table to grab the output
create table #cmmmand_output
	(	id int identity, 
		line varchar(8000))
-- build the command
SET 
	@command = '"C:\Microsoft SQL Server Migration Assistant for Oracle\bin\SSMAforOracleConsole.exe" -s "E:\ConversionAndDataMigration.xml" -v "E:\LV\VariableValueFile.xml"' 
--execute the command and grab the output lines
insert into #cmmmand_output(line)
EXEC master..xp_cmdshell @command

-- get the output result
select 
	line 
from 
	#cmmmand_output 
where 
	line is not null 
order by id

Open in new window

I also added a temp table to grab the command execution output. It is useful if you want to check for particular result, like if successful or not.
0
 
LVL 20

Expert Comment

by:netcmh
ID: 40031750
Thank you.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now