views:

1182

answers:

2

I am using Access 2007 (VBA - adp) front end with a SQL Server 2005 Backend. I have a report that i want to save a copy as a PDF as a binary file in the SQL Server.

1, Report Opened .
2, Report Closed - Closed Event Triggered.
3, Report Saved as PDF and uploaded into SQL Server table as Binary File.

Is this possible and how would i achive this?

+1  A: 

The easiest way to do this is to save the report out to disk as a PDF (if you don't know how to do that, I recommend this thread on the MSDN forums). After that, you'll need to use ADO to import the file using OLE embedding into a binary type of field. I'm rusty on that, so I can't give specifics, but Google searching has been iffy so far.

I'd recommend against storing PDF files in Access databases -- Jet has a strict limit to database size, and PDFs can fill up that limit if you're not careful. A better bet is to use OLE linking to the file, and retrieving it from disk each time the user asks for it.

The last bit of advice is to use an ObjectFrame to show the PDF on disk, which MSDN covers very well here.

A. Scagnelli
He doesn't want to save the PDF in the Access database (which I wouldn't recommend either), he wants to save it in the SQL Server database. I see no problem with that.
haarrrgh
I misread that and transposed backend and frontend. The advice for not storing PDFs in Access still stands: Jet has the hard limit that doesn't lend it to storing PDFs. For a MSSQL database, storing a PDF is perfectly fine.
A. Scagnelli
+3  A: 

There are different opinions if it's a good idea to store binary files in database tables or not. Some say it's ok, some prefer to save the files in the file system and only store the location of the file in the DB.

I'm one of those who say it's ok - we have a >440 GB SQL Server 2005 database in which we store PDF files and images. It runs perfectly well and we don't have any problems with it (for example with speed...that's usually one main argument of the "file system" people).

If you don't know how to save the files in the database, google "GetChunk" and "AppendChunk" and you will find examples like this one.

Concerning database design:
It's best if you make two tables: one only with an ID and the blob field (where the PDF files are stored in) and one with the ID and additional fields for filtering.
If you do it this way, all the searching and filtering will happen on the small table, and only when you know the ID of the file you want to load, you hit the big table exactly one time and load the file.
We do it like this and like I said before - the database contains nearly 450 GB of files, and we have no speed problems at all.

haarrrgh