Solved

XP_CMDSHELL ERROR (SQL SERVER 2005)

Posted on 2011-03-10
4
626 Views
Last Modified: 2012-05-11
Hi, Guys:

I have a need to execute a string from the command shell using xp_cmdshell (see below for script).

I am having problem getting the string in the correct “format”; I believe I need an escape character …????

I will appreciate your input, only if you can spare the time.

Thanks,


declare @sqlstr varchar(1000), @mlsnum varchar(16)
set @mlsnum = '11-512323'
--
set @sqlstr = (select top 1 '"C:\Program Files (x86)\Internet Explorer\iexplore.exe" http://www.themls.com/bingmaps/WS/GeocodeByHttp/?username=X64251&save=false&mlsnum=' +  @mlsnum) --cast(1234 as sysname)

print @sqlstr
-- above returns the string below:
-- "C:\Program Files (x86)\Internet Explorer\iexplore.exe" http://www.themls.com/bingmaps/WS/GeocodeByHttp/?username=X64251&save=true&mlsnum=11-512323
--
exec xp_cmdshell @sqlstr
--
-- above gives error below:
--'save' is not recognized as an internal or external command,
--operable program or batch file.
--'mlsnum' is not recognized as an internal or external command,
--operable program or batch file.
--NULL


-- NOTE:
--If I take the URL http://www.themls.com/bingmaps/WS/GeocodeByHttp/?username=X64251&false=true&mlsnum=11-512323
--and paste in IE, it works fine.
0
Comment
Question by:dteshome
  • 3
4 Comments
 
LVL 32

Expert Comment

by:ewangoya
ID: 35101966

include the parameter in quotes


set @sqlstr = (select top 1 '"C:\Program Files (x86)\Internet Explorer\iexplore.exe"  "http://www.themls.com/bingmaps/WS/GeocodeByHttp/?username=X64251&save=false&mlsnum=' +  @mlsnum + '"') --cast(1234 as sysname)

Open in new window

0
 

Author Comment

by:dteshome
ID: 35105799
It still gives the following error when the XP_... executes the string:

'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
'save' is not recognized as an internal or external command,
operable program or batch file.
'mlsnum' is not recognized as an internal or external command,
operable program or batch file.
NULL

However, when I took the string and run in the cmd shell it works.
0
 

Accepted Solution

by:
dteshome earned 0 total points
ID: 35159123
I figured it out!  The problem is with the "extended chars" - & etc.

Placing a ^ infront of the extended chars fixes the problem. Please see below

set @sqlstr = (select top 1 '"C:\Program Files (x86)\Internet Explorer\iexplore.exe" http://www.themls.com/bingmaps/WS/GeocodeByHttp/?username=X64251^&save=true^&mlsnum=' +  @mlsnum) --cast(1234 as sysname)
0
 

Author Closing Comment

by:dteshome
ID: 35187401
None of the sol'n given earlier worked.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
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.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

919 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

23 Experts available now in Live!

Get 1:1 Help Now