close
close
news

sql server – BCP exports result in file corruption for non-PDF files

What I’m trying to do is use Bulk Copy Program to extract data from a VARBINARY column of my database and then download files of various types (PDFs, XLSs, TIFs, etc) to the user’s hard drive.

At first I wasn’t able to generate a any files that I was actually able to open due to data corruption. Then once I started using an XML format file I’ve been able to generate and download PDF files that will open fine, but it still becomes corrupted with XLSs, TIFs, etc to the extent that the file either won’t open or if they do they’re pretty much unreadable. Word docs actually open okay but they are proceeded with a warning the ‘Word found unreadable content’.

This is the content of my format file:



 
  
 
 
  
 

And this is the command I’m using:

bcp "select CONTENTS from DOCUMENT_TABLE where DOC_ID = 123" queryout "C:\users\fred\bcp_files\BCP_results.xls" -c -d MyDatabase -S MyDatabaseServer  -f "C:\Users\fred\bcp_files\format_file.xml"

As I said it does fine with PDF files; the data gets corrupted with pretty much anything else.

Any suggestions?

Thank you

Related Articles

Back to top button