使用Asp.net将图像保存在数据库中

问题描述:

我想使用ASP.net在MSSQL服务器中保存大量的图片,哪种方法最好,以下为什么?

(1)在数据库中保存图像路径。

(2)将数据保存在数据库中。

I want to save large number of pics in MSSQL server using ASP.net which method is best from the following and why?
(1)Save image path in database.
(2)save image in database.

对于大图像,最常见的解决方案是将(唯一的)文件名存储在数据库中,并将文件本身在服务器端的文件系统中。



我将减少数据库负载和性能负担,允许ASP.NET应用程序直接将文件作为静态对象提供,无需数据库访问。此外,文件的物理存储可以在不同的计算机上,而不是在运行HTTP服务器的计算机上。



将所有文件存储在数据库中的一些好处将是更好的数据完整性。例如,您不需要单独备份数据库和单独备份映像文件。您不需要检查数据库是否与文件存储完全同步,这可能不是由于某些硬件故障造成的。嵌入在RDBMS中的事务机制不涉及外部文件存储,因此您需要单独处理完整性。



-SA
For big images, most usual solution is to store (unique) file names in a database, and files themselves in a file system of the server side.

I will reduce the database load and burden on its performance, allow ASP.NET application to serve files as static objects directly, without a need for database access. Also, the physical storage of the files could be on a different computer, not the on the one running the HTTP server.

Some benefit of storing it all on database would be better data integrity. For example, you would not need to backup database separately and image file storage separately. You won't need to check up if the database is perfectly synchronized with the file storage, which may not be the case as a result of certain, say, hardware faults. The transaction mechanism embedded in a RDBMS does not involve external file storage, so you would need to take care of the integrity separately.

—SA


请参阅:



在DB中存储图像 - 是或不是? [56 answers] [ ^ ]



做或不做:将图像存储在数据库中 [ ^ ]
See these :

Storing Images in DB - Yea or Nay? [56 answers][^]

To Do or Not to Do: Store Images in a Database[^]