November 14, 2003 at 2:03 pm
Hello,
Speaking of Xp_cmdshell.
The below command works fine:
declare @command varchar(1000)
SET @command='master..xp_cmdshell "E:\NewFolder\CreateDateFolder.exe"'
EXECUTE (@command)
However, when 'NewFolder' is being changed to 'New Folder' (with a space between 2 words)
I am getting an error.
Any ideas?
Also, can Xp_cmdshell pass parameters? And if yes, can you provide an example.
Thanks.
ad
November 14, 2003 at 3:38 pm
February 16, 2009 at 1:44 pm
Hi, I have created this procedure:
CREATE PROCEDURE ExecInsertCmd
-- Add the parameters for the stored procedure here
@Table varchar(255),
@InputFilePath varchar(5000)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
/*DECLARE @Table varchar(255)
DECLARE @InputFilePath varchar(5000)
SET @Table = 'tbl_tareatipo'
SET @InputFilePath = 'C:\Temp\PlutonDevScripts\Maestros\'
*/
-- Insert statements for procedure here
DECLARE @SQLCMDPath varchar(500)
DECLARE @SQLCMDInput varchar(500)
DECLARE @SQLCMDOutput varchar(500)
DECLARE @SQLCMD varchar(1500)
SET @SQLCMDPath = '"C:\Program Files\Microsoft SQL Server\90\Tools\Binn\sqlcmd.exe" -S gerencia -d Plutondev -E '
SET @SQLCMDInput = @InputFilePath + @Table +'.sql'
SET @SQLCMDOutput = @InputFilePath + @Table +'.out'
SET @SQLCMD = @SQLCMDPath + ' -i' + @SQLCMDInput + ' -o' + @SQLCMDOutput
EXEC('SET IDENTITY_INSERT ' + @Table + ' ON')
EXEC master..xp_cmdshell @SQLCMD
EXEC('SET IDENTITY_INSERT ' + @Table + ' OFF')
END
GO
Executed by this line: EXEC ExecInsertCmd 'tbl_tareatipo', 'C:\Temp\PlutonDevScripts\02Maestros\'
but havent been able to make it work.
The idea is that I am traying to run some insert scripts that requires the indentity insert set to on.
The errors that it gives me are:
'C:\Program' is not recognized as an internal or external command,operable program or batch file.'
And when I review the output of the generated file (.out):
Msg 544, Level 16, State 1, Server GERENCIA, Line 1
Cannot insert explicit value for identity column in table 'tbl_tareatipo' when IDENTITY_INSERT is set to OFF.
Any help would be appreciated.
Rgds
Ricardo
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply