question

priyav6 avatar image
priyav6 asked

PDf created from Blob field using OAMethod is damaged on sql 2008 r2

I am using following line in my stored procedure to create a pdf file from blob field (data type of image). EXEC @ObjectReturn= sp_OACreate 'ADODB.Stream', @ObjectToken OUTPUT EXEC @ObjectReturn=sp_OASetProperty @ObjectToken, 'Type', 1 EXEC @ObjectReturn=sp_OAMethod @ObjectToken, 'Open' EXEC @ObjectReturn=sp_OAMethod @ObjectToken, 'Write', NULL, @BlobToDisk IF @ObjectReturn<>0 BEGIN EXEC sp_OAGetErrorInfo @ObjectReturn, @src OUT, @desc OUT raiserror('Error Creating SaveToFile Component 0x%x, %s, %s',16,1, @hr, @src, @desc) RETURN END EXEC @ObjectReturn=sp_OAMethod @ObjectToken, 'SaveToFile', NULL, @InFileName, 2 EXEC sp_OAMethod @ObjectToken, 'Close' EXEC sp_OADestroy @ObjectToken InFileName is set to a valid folder location with file extension of .pdf example : c:/PDFDocs/ test.pdf The stored proc executes fine and pdf file gets created. However, when I try to open this pdf file I get a message in reader saying file is damaged. The same stored proc works absolutely fine on sql server 2012 r2. I am facing this problem only on 2008 r2. Please help!
sql server 2008blobpdf
1 comment
10 |1200

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

This web site runs off of votes. Can you please indicate all helpful answers below by clicking on the thumbs up next to those answers. If any one answer lead to a solution, please indicate that by clicking on the check mark next to that one answer.
0 Likes 0 ·

1 Answer

·
Phil Factor avatar image
Phil Factor answered
I'm not sure why this is happening but I can't help noticing that you are only checking the object automation errors in one place (write) and I know from bitter experience that errors can happen in any OA operation. One other thing caught my eye. Shouldn't the option for SaveOptionsEnum be 3 just in case the file already exists?
1 comment
10 |1200

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

@John: Thanks for editing @Phil: Thanks for looking into it. I have figured out it could be a volume license issue for MS office on 2008 server and 2012 server has one, its working fine while converting .doc blobs to pdf, if it even makes sense. Thanks for the other suggestions, but the part I have pasted is trimmed down for posting here, ass the check and errors are raised in actual sp.
0 Likes 0 ·

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.