Solved

execute operating system command in sql job

Posted on 2014-04-10
7
278 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sql server function help 15 31
MS SQL + Insert Into Table - If Doesnt Exist 9 35
Connecting to multiple databases to create a Dashboard 5 26
T-SQL:  Collapsing 9 25
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

803 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