views:

78

answers:

2

I am building an ASP.Net C# web application that will be using lots of sound files and image files. Considering performance, would it be best to store all files in SQL as image data type and retrieve from the database or store/archive the hard file on the server and store the path in sql? Im curious about the pros and cons - other than the obvious of storage space and manageability.

A: 

From a performance perspective you should be better off storing the sounds/images as files and just keeping a reference to the location in the database. This will save you from having to transfer the data from the database to the web server and reconstitute the "file" via a handler whenever it is referenced. Of course, caching could help this but you'd still pay the penalty on each cache miss. This solution is also, for my money, somewhat less complicated in terms of the code that needs to be developed though you do have issues with collisions and some extra security setup (potentially) to do if you are enabling upload.

tvanfosson
A: 

My current client is currently looking at the same options. There are a few tradeoffs to consider:

Storing as IMAGE data type:

  • You only need to backup your database rather than the DB and places on the file system
  • You don't have to worry about files being moved without the DB being updated with the new location or any other issues with hanging pointers to non-existent files

Storing as a file with a path in the DB:

  • Slightly faster access (we'll be quantifying this in the next few days)

Originally I thought that there would also be a problem with client-side caching of images. For example, when .NET gets the image out of the DB the client browser can't cache it - it looks like a new image every time. I then learned that unless you are giving users file-level access (a security no-no) you run into the same problem using direct file access.

Tom H.