Ok - create a table called DebugSproc_T
Code:
Create Table DebugSproc_T
(DId int identity not null
,DMessage varchar(1000)
,TDate datetime
,Constraint PKDebugSproc
Primary Key (DId)
)
Now alter your sproc to be
Code:
CREATE PROCEDURE [dbo].[My_XP_CMDSHELL_BCP_SELECT_FOR_XML]
AS
Insert into DebugSproc_T values ('In Here',GetDate())
DECLARE @FileName varchar(50),
@bcpCommand varchar(2000)
SET @FileName = REPLACE('c:\temp\WinSrvc_SP_BCP_OUT_XML_'+CONVERT(char(8),GETDATE(),1)+'.xml','/','-')
Insert into DebugSproc_T values (@FileName,GetDate())
SET @bcpCommand = 'bcp "SELECT CategoryID, CategoryName FROM Northwind.dbo.Categories [Categories] FOR XML AUTO, ROOT(''NewDataSet''), ELEMENTS" QUERYOUT "'
SET @bcpCommand = @bcpCommand + @FileName + '" -SMAIN\SQL2008 -T -c -r -t'
--PRINT @bcpCommand
Insert into DebugSproc_T values (@bcpcommand,GetDate())
EXEC master..xp_cmdshell @bcpCommand, No_output
Insert into DebugSproc_T values ('About to leave',GetDate())
GO
You can also put CATCH/BEGIN's in the SPROC to detect errors and put them to DebugSproc_T