将文件存储在文件服务器上还是数据库中?
我正在 ASP.Net 中开发一些网络应用程序,主要是关于存储、共享和处理 MS Word doc 和 PDF 文件,但我不知道如何管理这些文档,我正在考虑将文档保存在文件夹中,只保留将它们的元数据保存在数据库中或将整个文档保存在数据库中,我正在使用 SQL Server 2008。您的建议是什么?
I'm developing some web app in ASP.Net which is mainly about Storing, Sharing and Processing MS Word doc and PDF files, but I'm not sure how to manage these documents, I was thinking of keeping documents in folders and only keeping metadata of them in DB OR keeping the whole documents in DB,I'm using SQL Server 2008. what's your suggestion?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
SQL Server 2008 在存储和提供大型文档方面相当出色(与某些早期版本不同),因此它绝对是一个选择。也就是说,从数据库提供大型 blob 通常不是一个好主意。我认为您需要考虑这两种方法的优点和缺点。需要考虑的一些一般事项:
我相信实施存储到数据库的解决方案可能会更快,但存储到文件系统通常是更好的解决方案。然而,在后一种情况下,您将不得不担心一些问题,例如具有唯一的文件名,并且通常不希望在单个文件夹中存储太多文档(大多数解决方案在每几千个文档后创建新文件夹)。如果文件不会很多且不会很大,请使用更快的方法,否则需要花费一些时间在文件系统上存储。
SQL Server 2008 is reasonably good at storing and serving up large documents (unlike some of the earlier versions), so it is definitely an option. That said, having large blobs being served up from the DB is generally not a great idea. I think you need to think about the advantages and disadvantages of both approaches. Some general things to think about:
I believe it's probably quicker to implement a solution that stores to the DB, but that storing to the file system is generally the superior solution. In the latter case, however, you will have to worry about some issues, such as having unique file names, and in general not wanting to store too many documents in a single folder (most solutions create new folders after every few thousand documents). Use the quicker approach if the files are not going to be numerous and large, otherwise invest some time in storing on the file system.
在数据库中,除非您不关心数据完整性。
如果您将文档存储在数据库之外,您迟早会丢失文档和损坏的链接。您的备份/恢复场景要复杂得多:您无法确保所有数据都来自同一时间点。
SQL Server 2008 中的 FILESTREAM 使其现在变得高效(其他 RDBMS 也具有类似的功能)
In the database unless you don't care about data integrity.
If you store docs outside of the database you will have missing documents and broken links soomer not later. Your backup/restore scenario is a lot more complex: you have no way to ensure that all data is from the same point in time.
FILESTREAM in SQL Server 2008 makes it efficient nowadays (and other RDBMS have features like this too)
如果您将这些文件存储在一个文件夹中,则在数据库中维护文件名。由于任何目录都不能有两个文件名相同且扩展名相同的文件。如果你想将文件存储到DB中,那么你可能必须使用BLOB或字节数组来存储。
我看到打开数据库连接的开销,尽管我不知道数据库连接与 file.Open 相比有多快(甚至性能方面)。
If your storing these files in one folder, then maintain the files names in the DB. Since no dir can have 2 files names same with same extension. If you wish to store the file into DB, then you may have to use BLOB or byte array to store.
I see over head in opening a connection to the DB, though i dont know how fast the DB connection is compared to file.Open (even peformance wise).
如果文件相对较小,我会将它们作为 BLOB 字段存储在数据库中。这样您就可以使用标准程序进行备份/恢复以及事务。如果文件很大,则将它们保留在硬盘驱动器上并将文件名存储在数据库中(如前面建议的那样)有一些优点
If files are relatively small I would store them as BLOB fields in database. This way you can use standard procedures for backup/restore as well as transactions. If files are large there are some advantages in keeping them on the hard drive and storing filenames in the database as was suggested earlier
您计划存储多少文档?
数据库方法的主要优点是正常的 ACID 属性 - 元数据将始终是与文档一致,如果使用文件系统来存储文档就不会出现这种情况。使用文件系统,您的元数据和文档相对容易不同步:文件系统上的文档没有元数据,文档的元数据丢失或损坏。如果您需要文档存储的任何可靠性,那么数据库是比使用文件系统更好的方法。
How many documents are you planning to store?
The main advantage of the database approach is the normal ACID properties--the meta-data will always be consistent with the document, which will not be the case if you use the file system to store the documents. Using the file system it would be relatively easy for your meta-data and documents to get out of sync: documents on the file system for which there is no meta-data, meta-data where the document has gone missing or is corrupted. If you need any sort of reliability in your document storage, then the database is a much better approach than using the file system.
如果您仅对这些文件进行操作,我会考虑将它们存储在数据库中,就像
BLOB
数据一样。如果您的文件夹中有文件并且数据库中只有名称,您应该关心以下事实:1)有一天您可能需要重命名文件
2)更改其位置
3)更改其扩展名
或其他内容。
如果是DB,您可以将数据保存在单独的表
BLOB
中,在其他表名称和扩展名中文件及其BLOB
表上的 ID。在这种情况下,在前面讨论的场景中,您只需要执行简单的 SQL 更新查询。If you are going only operate on that files I would think to store them i DB like a
BLOB
data. In case if you have a files on folders and only names in DB, you should care about the fact that, for example:1) one day you may need rename file
2) change its location
3) change its extension
or whatever.
In case of DB instead, you can save in separate table
BLOB
data, in other table name and extension of the file along with its ID onBLOB
table. In this case, in moment of previously discussed scenario you will need just execute simple SQL update query.