Reputation: 4165
I have been playing around with creation of pdf documents for a project that I'm working on. I would like to store the generated pdf document in a SQL database and then later be able to retrieve this pdf as well.
What are some suggestions for doing this? Can the document be stored in the database without physically creating the document on the server?
Upvotes: 1
Views: 1979
Reputation: 1
You have 2 ways to do that:
I recomend that you use the second..
why I choose that answer?? for security.
One of a lot of reasons: A little Example:
If you do the Firt(store the file in the fileserver...) you are crating a folder on your database.. so you server will be vulnerable for attacks or for virus..
If you do the second. the file will be encode and store in database and you dont need to be worried about attacks or machine infections..
I think that this are 1 simple reason about why never use the first WAY!!!!!
Upvotes: 0
Reputation: 17957
You can use a table like this to store files in SQL Server.
CREATE TABLE [Documents]
(
[FileName] nvarchar(1000),
[FileContent] varbinary(max)
)
Upvotes: 0
Reputation: 161783
Keep in mind that SQL Server 2008 now has the FILESTREAM
data type. You can write the data to the file system, yet still store it in a column.
Upvotes: 1
Reputation: 7541
This is again going to bring up the debate for/against storing things on the file system or within sql server itself.
It really depends on your needs, the size that you're expected, etc. Here are some references, each with more references.
Storing a file in a database as opposed to the file system?
store image in database or in a system file?
Upvotes: 1
Reputation: 50493
Save the PDF as a byte[]
then you can use itextsharp
to created the PDF when ready for viewing.
Upvotes: 0
Reputation: 115488
What are some suggestions for doing this? Can the document be stored in the database without physically creating the document on the server?
Sure just create the pdf as a byte stream (byte[]
) and store it in the database. Depending on what you use to create it, you don't have to write it to the file system.
Actually, on the argument about where to store it. If you have SQL server 2008, you want to use that. It will store the file on the file system, but you can access it through the database like you would with any other data. You get the best of both worlds.
Upvotes: 1