Best way to save/load pictures with .Net & SQL Server 2005?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-05 21:23:33

Saving files on filesystem but inside a DB
Saving files into DB makes it a single backup point for all your application data and makes a smaller security surface for your app because you don't need a write permission folder for storing files.

SQL Server 2008 FILESTREAM storage to the rescue

With SQL Server 2008 Microsoft introduced a new data storage mechanism called FILESTREAM that stores data in folders as regular files. But you can access them (and store their metadata) via tables. You can store files as varbinary(max) and they get stored on the filesystem as configured. These files will also get picked up by DB Backup procedure. This way you get the best of both worlds in a single solution.

Read about it here.

Post-festum note
I have to point out that authors of the question did mention they may use SQL Server 2008 as well when there are any benefits. That's the only reason this answer is related to version 2008, because this really is the optimal solution for their problem.

Mitch Wheat

Please see: Storing a file in a database as opposed to the file system?

I have working C# code for SQL Server 2005 if you decide to store in the Database here: Save and Restore Files/Images to SQL Server Database

This MS Research paper by the late Jim Gray: To BLOB or Not To BLOB: Large Object Storage in a Database or a Filesystem has the following advice:

As expected from the common wisdom, objects smaller than 256K are best stored in a database while objects larger than 1M are best stored in the filesystem. Between 256K and 1M, the read:write ratio and rate of object overwrite or replacement are important factors.

Don't load DBMS by binary data! Let SQL Server do its specific work. It is better when files stored in file system and even on other computer.

My preferred solution is always to save them to a directory on your file system and save the url / location in the database. I find this the easiest to maintain and it's easy to change databases, datastorage without affecting the files.

This method, is not dependent on the database.

I had a situation recently where a legacy system stored images and files as binary, which caused time and effort retrieving these to upgrade database software.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!