Solved

XP_CMDSHELL ERROR (SQL SERVER 2005)

Posted on 2011-03-10
4
621 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
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.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

746 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

12 Experts available now in Live!

Get 1:1 Help Now