teknowcat avatar image
teknowcat asked

SQL Image Extraction Problem

Hi All, I'm trying to extract images from a restored database. The script below ostensibly runs fine: meaning it extracts the images and saves the number of files I expect to see (and the size I would expect to see) into a network folder as .pdf files. However, when I try to open the files this is the error message I receive: *Adobe Reader could not open ' filename.pdf' because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded).* 1. I have run this script before in other environments (2 to be exact) and it's worked fine. 2. I have verified that the actual images are good. You can access the files via the front end. 3. It doesn't appear that the values are encrypted. Although I'm not completely sure. 4. The Data Type natively is: image 5. I've been using SQL for a while but would consider myself a noob, whereas, I'm basically self-taught -so please go easy. Any guidance / suggestions / insight will be very much welcome. --======================================================================== USE < > GO sp_configure 'show advanced options', 1 GO RECONFIGURE; GO sp_configure 'Ole Automation Procedures', 1 GO RECONFIGURE GO DECLARE @FILEID VARCHAR(12), @IMAGE VARBINARY(MAX), @OBJSTREAM INT, @FILENAME VARCHAR(MAX), @BASEDIR VARCHAR(MAX) SET @BASEDIR = '< >' PRINT 'BASEDIR: ' + @BASEDIR DECLARE IMGEXTRACT CURSOR FAST_FORWARD FOR select < >, < > from < > OPEN IMGEXTRACT FETCH NEXT FROM IMGEXTRACT INTO @FILEID, @IMAGE WHILE @@FETCH_STATUS = 0 BEGIN SET @FILENAME = @BASEDIR + '\' + @FILEID + '.pdf' PRINT @FILENAME EXEC sp_OACreate 'ADODB.Stream', @OBJSTREAM OUTPUT EXEC sp_OASetProperty @OBJSTREAM, 'Type', 1 EXEC sp_OAMethod @OBJSTREAM, 'Open' EXEC sp_OAMethod @OBJSTREAM, 'Write', NULL, @IMAGE EXEC sp_OAMethod @OBJSTREAM, 'SaveToFile', NULL, @FILENAME, 2 EXEC sp_OAMethod @OBJSTREAM, 'Close' EXEC sp_OADestroy @OBJSTREAM FETCH NEXT FROM IMGEXTRACT INTO @FILEID, @IMAGE END CLOSE IMGEXTRACT DEALLOCATE IMGEXTRACT GO --======================================================================== Thank you.
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

0 Answers

· Write an Answer

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.