Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WinForms application design - moving documents from SQL Server to file storage

I have a standard WinForms application that connects to a SQL Server. The application allows users to upload documents which are currently stored in the database, in a table using an image column.

I need to change this approach so the documents are stored as files and a link to the file is stored in the database table.

Using the current approach - when the user uploads a document they are shielded from how this is stored, as they have a connection to the database they do not need to know anything about where the files are stored, no special directory permissions etc are required. If I set up a network share for the documents I want to avoid any IT issues such as the users having to have access to this directory to upload to or access existing documents.

What are the options available to do this? I thought of having a temporary database where the documents are uploaded to in the same way as the current approach and then a process running on the server to save these to the file store. This database could then be deleted and recreated to reclaim any space. Are there any better approaches?

ADDITIONAL INFO: There is no web server element to my application so I do not think a WCF service is possible

like image 662
Gary Joynes Avatar asked Mar 29 '26 16:03

Gary Joynes


1 Answers

Is there a reason why you want to get the files out of the database in the first place?

How about still saving them in SQL Server, but using a FILESTREAM column instead of IMAGE?

Quote from the link:

FILESTREAM enables SQL Server-based applications to store unstructured data, such as documents and images, on the file system. Applications can leverage the rich streaming APIs and performance of the file system and at the same time maintain transactional consistency between the unstructured data and corresponding structured data.

FILESTREAM integrates the SQL Server Database Engine with an NTFS file system by storing varbinary(max) binary large object (BLOB) data as files on the file system. Transact-SQL statements can insert, update, query, search, and back up FILESTREAM data. Win32 file system interfaces provide streaming access to the data.

FILESTREAM uses the NT system cache for caching file data. This helps reduce any effect that FILESTREAM data might have on Database Engine performance. The SQL Server buffer pool is not used; therefore, this memory is available for query processing.

So you would get the best out of both worlds:
The files would be stored as files on the hard disk (probabl faster compared to storing them in the database), but you don't have to care about file shares, permissions etc.

Note that you need at least SQL Server 2008 to use FILESTREAM.

like image 58
Christian Specht Avatar answered Apr 02 '26 06:04

Christian Specht



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!