I am trying to save data from a table directly to the servers file system using this t-sql:
DECLARE @ID int
DECLARE @command varchar(1000)
DECLARE @Name varchar(100)
DECLARE @FileName varchar(100)
DECLARE MyCursor CURSOR FOR
SELECT Id, [FileName] FROM FilesTable
OPEN MyCursor
FETCH NEXT FROM MyCursor
INTO @ID, @Name
WHILE @@FETCH_STATUS = 0
BEGIN
SELECT @FileName = 'd:\Temp\' + convert(varchar(200), @Name)
SET @command = 'bcp "SELECT FileBytes FROM FilesTable WHERE ID = ' + convert(varchar(18), @Id) + '" queryout "' + @FileName + '" -T -n'
EXEC master..xp_cmdshell @command, no_output
FETCH NEXT FROM MyCursor
INTO @Id, @Name
END
CLOSE MyCursor
DEALLOCATE MyCursor
The table is filled with solid data. accessing this data with a C# program works. I did configure advanced options gave permission to use xp_cmdshell When I run this query i don't get any error but no file was written. I also don't see anything in the logs, (maybe I am looking in the wrong location?)
What am I doing wrong? Or what can I do to checdk 'under the hood'?