将文件保存在数据库中VS将文件保存在不同服务器的硬盘上 [英] Saving files in a database VS saving files on the hard disk in a different server

查看:100
本文介绍了将文件保存在数据库中VS将文件保存在不同服务器的硬盘上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI,



我需要保存从托管的Web应用程序上传的不同类型的文件(图像,文档,xls等)。但问题是我无法将这些文件保存在托管Web应用程序的同一台服务器上,而是需要将它们保存在数据库服务器上。我提出了两种方法 -

1.将文件保存在SQL数据库中并直接从数据库中检索它们。

2.创建并托管Web /数据库服务器上的WCF服务将文件保存在数据库服务器的硬盘中,以后再根据客户端请求检索文件。



任何人都可以建议我哪一个会更好。



I need to save files of different types (images, docs, xls etc.) uploaded from a hosted web application. But the issue is that I can't save those files on the same server on which the web app is hosted, rather I need to save them on the database server. I have come up with two approaches -
1. Saving the files in the SQL Database and retrieve them directly from the database only.
2. Create and host a web/WCF service on the database server to save the files in the database server's hard disk, and later on retrieve the files on client request.

Can anybody suggest me which one will be a better approach.

推荐答案

取决于。

我同时做这两件事:一些文件进入数据库,另一些进入文件夹,进入数据库的链接。一般来说,决定我走哪条路的大小是:如果文件很大==>夹。如果它们很小==>数据库。



你要避免的是通过大量数据传输堵塞数据库:文件系统习惯了,但数据越大,数据库内存越多服务器必须分配,它用于传输的带宽越多,等等。



如果你将它们存储在一个文件夹中,那么就不要使用原始文件name:使用文件链接将其保存在DB中,并为文件提供临时名称 - 我使用Guids - 以避免在获得两个具有相同文件名的用户时出现问题。
Depends.
I do both: some files go in the DB, other go in folders, with links to them going into the DB. Generally, what decides which way I go is size: if the files are large ==> folder. If they are small ==> database.

What you want to avoid is clogging up the DB with huge data transfers: file systems are used to that but the bigger the data, the more memory the DB server has to allocate, the more bandwidth it uses to transfer, and so forth.

If you do store them in a folder, then don't use the original file name: keep that in the DB with the file link, and give the file a temporary name - I use Guids - to avoid problems when you get two users with the same file name.


I不完全不同意Griff(谁可以?),但SQL Server中大文件的另一个选择是使用Filestream数据类型将文件存储在数据库中。然后,这些文件由SQL Server存储在文件系统中,并使用SQL查询进行检索。



我总是对在DMZ外部访问Web应用程序感到不安,除了通过数据库连接。这也让我的IT人员感到高兴!
I don't entirely disagree with Griff (who could?), but another option for large files in SQL Server is to store the files in a database using the Filestream data type. The files are then stored in the file system by SQL Server and retrieved using SQL queries.

I always feel uneasy about giving access outside of the DMZ to a web application, except through a database connection. That also keeps my IT guys happy!


这篇关于将文件保存在数据库中VS将文件保存在不同服务器的硬盘上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆