Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a SQL table to store information about documents that where sent to customers.

Table
timestamp [datetime2(0)]
customerID [nvarchar(50)]
fileOk [bit]
folder [nvarchar(max)]
file1 [nvarchar(255)]


Example
timestamp            customerID    fileOk    folder         file1
2018-08-13 14:20:00  C920987238    1         /docFolder/    customerdoc1.pdf


The table consists of some 100.000 rows.
Is there a way to bind the table to an existing directory?
Say I delete a file in the folder the field fileOk is autmatically set to 0?
Or if I add a file to the folder an new default entry is created?

What I have tried:

Used a custom script (C#) which does the job.
Posted
Updated 13-Aug-18 5:05am
Comments
CHill60 13-Aug-18 8:56am    
AFAIK you'll have to write a file watcher to do that for you
littleGreenDude 13-Aug-18 11:18am    
Please check out https://www.codeproject.com/Articles/26528/C-Application-to-Watch-a-File-or-Directory-using-F
Sni.DelWoods 17-Aug-18 7:50am    
A filewatcher is what I already have. Application checks the directory and Updates the database.

1 solution

The only native SQL Server functionally that I am aware of would be to implement a FileTable, which would create a directory in the local file system to house the files.
Standard file system processes would be atomic with the table within SQL, and then triggers could be utilized to update your current table.

Documentation:
Load files into FileTable[^]
FileTables- Trigger Compatability[^]

I personally would stick with a programming code solution.
 
Share this answer
 
Comments
Sni.DelWoods 17-Aug-18 7:53am    
Thanks for that. The Microsoft way of filetable is very .....poor. Would have been to easy to link just a table field to a file or something like that.

The code solution apart from the sql server seems indeed to be the best solution.
MadMyche 17-Aug-18 12:42pm    
I really don't care for files inside of the DB; an additional service is required to maintain the FileSystem:Database relationship intact.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900