Symptoms

When you attempt to run Report Commander from a SQL Server stored procedure using xp_cmdshell, the command fails with the following error:

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

Cause

This happens because xp_cmdshell does not work correctly with more than one set of double quotes in the command to execute.

For example, assume you are using an approach similar to the following:


declare @cmd nvarchar(1000)
set @cmd = '"c:\Program Files\Arcana Development\Report Commander 2\adcrutil.exe" -report="MyReport.rpt" ...'
EXEC xp_cmdshell @cmd

xp_cmdshell strips the first double quote in this case, and as a result the command interpreter does not correctly process the path with embedded spaces.

Workaround

One workaround that may resolve this problem is to include a "call" statement at the beginning of the command:


declare @cmd nvarchar(1000)
set @cmd = 'call "c:\Program Files\Arcana Development\Report Commander 2\adcrutil.exe" -report="MyReport.rpt" ...'
EXEC xp_cmdshell @cmd

If this is not effective, it may be necessary to place the Report Commander command in a batch file that can be called by xp_cmdshell, or to search the web for alternative workarounds.

Status

This issue is due to a limitation of the xp_cmdshell procedure in SQL Server. Refer to the xp_cmdshell documentation for more information.