Solved

XP_CMDSHELL ERROR (SQL SERVER 2005)

Posted on 2011-03-10
4
633 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:Ephraim Wangoya
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

Free Webinar: AWS Backup & DR

Join our upcoming webinar with experts from AWS, CloudBerry Lab, and the Town of Edgartown IT to discuss best practices for simplifying online backup management and cutting costs.

Question has a verified solution.

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

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how the fundamental information of how to create a table.

685 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