Click here to Skip to main content
15,920,602 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hai Frieds,
I wanna store image files , pdf and sound files in my application.What is the best method of storing these type of files.Is it possible with sql server 2005 ?, how ? ,any problem in future ?

Thanks adv
Posted

There are, effectively, two options for storing your files. It's worth considering what the reasoning behind these methods are before you make your choice. The first option is to keep your files in the file system, and just store the location in the database (also including information such as the original filename).
  • If there's a potential that you are going to move to a different database, then this is a simpler option than recreating the files from the database, and reuploading them in the new database format.
  • Storing the files gives you more choices for retrieving the files, without having to write your own custom extraction routines.
  • If you're using the express edition of SQL Server 20005, there's a 2GB limit to it's size. This would soon fill up if you were using files.
  • Depending on what you want to do, e.g. just have a link to the file on a web page, this could require you to have to extract the files and write them to a temporary location which would need clearing up. If you just store the file on the disk, you don't have to worry about this, and the link will be quicker to generate.

The alternative is to store the file in the database. Here are some reasons for this option:
  • If you have an archive strategy in place, e.g. removing old files, then it's a lot more work to have to maintain two change points which are independent of each other. In other words, if you store the file on the disk and you move it, you also have to update the database - but what happens if the database update fails? You have broken the connection between the file and the data row that points to it.
  • If you upload files to storage, you have to ensure that the filenames are unique. This would mean saving the file with a randomly assigned name (probably a GUID), and storing a mapping in the database between the two. If the file is in the database, there is no need to change the filename.
  • Storing the file on the file system requires write permissions to the file storage location. Granting this access may not always be possible.

So, whichever option you choose is up to you, once you have weighed up the above considerations.
 
Share this answer
 
Comments
thatraja 6-Mar-12 6:53am    
Nice, 5!
Pete O'Hanlon 6-Mar-12 7:12am    
Thanks mate.
thatraja 6-Mar-12 10:59am    
Glad to see you here mate. Please do this whenever possible.
Luc almost panned Q/A section :sigh: Here in Q/A section I found more than bunch of interesting questions & I always wanted to see answers from people like you.

Cheers!
El_Codero 6-Mar-12 7:14am    
Nice explanation, 5!
Abhinav S 6-Mar-12 7:18am    
Perfect. 5.
yah its possible to store in DB as byte array.but i would suggest to store the images, files & pdf in the folder instead of DB.
if you store in the DB, it will make your DB more bulky. store the file path in the database. problems like it will make your database more bulky, maintenance cost will be more, speed will hamper.
 
Share this answer
 

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