Save PDF file to SQL database

I am using C#. I want to store PDF files from a Windows forms application to a SQL database. And I want to retrieve it to my Windows Forms application again. What controls can I use to upload PDF files (for example for image I use picture box). What is the data type for PDF files? Thanks in advance

750k 181 181 gold badges 1.4k 1.4k silver badges 1.5k 1.5k bronze badges asked Mar 8, 2014 at 7:04 55 1 1 gold badge 1 1 silver badge 3 3 bronze badges

5 Answers 5

To select a file you can use OpenFileDialog

1 1 1 silver badge answered Mar 8, 2014 at 7:28 Mihai Hantea Mihai Hantea 1,743 13 13 silver badges 17 17 bronze badges

You'd better store pdf in file storage and save link to it in database.

answered Mar 8, 2014 at 7:12 758 9 9 silver badges 29 29 bronze badges

I hear varying arguments about this. Apparently there is a breaking point at 256kb where the pdf gets fragmented in the database then affects performance and you should switch to file storage. But I don't see pdf documents as being over the 256kb limit.

Commented May 29, 2017 at 20:31

If you work with light pdf like application forms 256kb that's ok. But when someone starts upload 60mb scans you become worried.

Commented May 29, 2017 at 20:41

To store a PDF file in your SQL Server Database, you need to store the contents of the file in BinaryData field. However, I am sure that you will face so many problem with this setup, that you would do better to save your file contents in the SystemData folder and just store the file path or name in to DB.

This will be much more reliable and easy to maintain.

Another approach if your application is storing only files, is to use MongoDb instead of SQL Server. I am not familiar with that, but quite sure that this will be an easy and good solution.