How to best store documents in a MS Sql database

Posts   
 
    
erichar11
User
Posts: 268
Joined: 08-Dec-2003
# Posted on: 12-Sep-2005 20:42:32   

Been googling trying to detemine the most appropriate way to accomplish this. I see some store documents as a blob field and others use an image field. But no real explanation of when to use what. So looking for some advice. To give a bit of background, in my app I want the user to be able to upload and download word, excel, text, powerpoint, basically any type of file from within the application.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39801
Joined: 17-Aug-2003
# Posted on: 12-Sep-2005 21:26:30   

2 approaches: 1) store the file in the filesystem and store the path to the file in the db 2) store the file in the db.

2) requires a lot of diskspace on the db server, and requires that the db / catalog can expand rapidly and without problems. 1) doesn't have that, but has the disadvantage that with backups you have to backup folders together with the database. Another downside is that when the files move to another folder, you're in for some db fun simple_smile

When you opt for 2), read the files into a byte[] and store that into an image column.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 20
Joined: 06-Sep-2005
# Posted on: 12-Sep-2005 22:59:25   

just to add to that, storage in the DB used to be more common before the widespread presence of Windows servers. Then, the DB was good since you did not have to account for bit-ordring and similar ugliness. Now, the situation is different and there is bound to be a Windows server nearby to store files easily.

pilotboba
User
Posts: 434
Joined: 05-Aug-2005
# Posted on: 13-Sep-2005 16:19:01   

Otis wrote:

Another downside is that when the files move to another folder, you're in for some db fun simple_smile

Of course, you can mitigate that by storing a base file path in a config table/file somewhere and make all paths that you store relative to that base path.

One other advantage of storing in a BLOB field is that full text indexs will index word and excel text.

BOb

wayne avatar
wayne
User
Posts: 611
Joined: 07-Apr-2004
# Posted on: 13-Sep-2005 22:26:50   

We store the path in the DB. Storing the path in the DB prevents your DB from becoming sluggish or bloated or so i was told.

For background Info: The actual file is on a ftp server - Not on the same machine. - The company scans TONS of images and we store that on a different Server.

erichar11
User
Posts: 268
Joined: 08-Dec-2003
# Posted on: 15-Sep-2005 14:07:13   

Thanks guys for the info. One question, why an image column vs. blob? Sounds as if a blob can be searched where an image column cannot. Is this correct? Is it the primarly difference. Thanks.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39801
Joined: 17-Aug-2003
# Posted on: 15-Sep-2005 15:26:00   

True, but a word doc isn't a textfile, it's a binary file. It contains '0's which means that you can't use it as a string, and therefore should use a blob simple_smile

Frans Bouma | Lead developer LLBLGen Pro