1

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'?

amaters
  • 2,266
  • 2
  • 24
  • 44
  • 1
    You might find help here: http://stackoverflow.com/questions/10325338/fastest-way-to-export-blobs-from-table-into-individual-files [1]: – Patrick Jul 06 '12 at 12:39

1 Answers1

0

Based on the comment from Patrick and the answer in fastest way to export blobs from table into individual files I was able to store the images on my fileserver.

we ended up writing a CLR function something like the one given.

Community
  • 1
  • 1
amaters
  • 2,266
  • 2
  • 24
  • 44