我们可以在Sql server 2008中存储文件(Word,Excel,Powerpoint,pdf)吗? [英] Can we store Files( Word, Excel, Powerpoint, pdf) in Sql server 2008?

查看:202
本文介绍了我们可以在Sql server 2008中存储文件(Word,Excel,Powerpoint,pdf)吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

盖伊!



我对sql server和c#有些怀疑。我只是想知道我们可以在Sql server 2008中存储文件(Word,Excel,Powerpoint,pdf)还是我们只能存储FilePath(文件目的地特别是硬盘)?我从互联网上了解到我们可以在sql server中存储文件,但只有二进制格式才是真的吗?



请帮帮我谢谢!

Hi Guy!

I have some doubt in sql server and c#. I just wanted to know that Can we store Files( Word, Excel, Powerpoint, pdf) in Sql server 2008 OR we can store only the FilePath (File destination in particular harddrive)? I have learned from internet that we can store files in sql server but only in binary format is it true?

Please Help me Thanks!!

推荐答案

你可以在SQL服务器中存储任何数据,如果你需要 - 你没有*将它们存储为二进制,因为VARCHAR(MAX)将接受高达2GB的数据,但无论如何,这可能是一个好主意,如PDF文件(和某些版本的Word)无论如何,excel文件都是二进制数据,如果存储在文本字段中,则可能无效。但是没关系 - 二进制不是问题,因为所有文件都以二进制形式存储在你的硬盘上!



别忘了当你将它作为下载发送给用户,你只需提供文件名和数据 - 它将保存在另一端,一切都会好的。
You can store any data in SQL server, if you need to - you don''t *have* to store them as Binary as VARCHAR(MAX) will accept up to 2GB of data, but it is probably a good idea to do so anyway, as PDF files (and some versions of Word and excel files) are binary data anyway, and may not work if stored in a text field. But that''s ok - binary isn''t a problem, because all files are stored on your HDD in binary anyway!

Don''t forget that when you send it back to the user as a download, you will just provide the file name and the data - it will be saved at the other end and all will be fine.


是的,你可以做使用 varbinary

例如,尝试

http://chiragrdarji.wordpress.com/2007/08/31/storing-and-retrieving-docpdfxls-files-in-sql-server/ [ ^ ]
Yes you can do that using varbinary.
For examples, try
http://chiragrdarji.wordpress.com/2007/08/31/storing-and-retrieving-docpdfxls-files-in-sql-server/[^]


实际上所有文件都是二进制格式。没有别的。

但我建议你不要将文件存储在数据库本身。它可以变得非常大,在大多数情况下,你将无法获得任何东西。 Sql Server的一个功能叫做 FILESTREAM [ ^ ]。例如,它与.net的文件流无关。此功能使您可以拥有在数据库中存储文件的所有专业人员,并且您存储的文件实际上由sql server管理(您有备份等),但它们不存储在数据库中,而是存储在文件系统中。您可以通过多种方式访问​​它们,如果您想要远程访问,甚至可以使用共享。它的主要优点是你不需要在这样的操作过程中对sql server施加巨大的负担。

当然,你也有办法从c#处理它们。

请参阅以下文章:我如何:使用SQL文件流 [ ^ ]

http://blogs.microsoft.co.il/blogs/bursteg/archive/2008/05/12/ado-net-entity-framework-support-filestream.aspx [ ^ ]
Actually all files are in binary format. There is nothing else.
But I suggest you not to store the file in the database itself. It can grow really large, and in most cases you will gain nothing with it. There is a feature of Sql Server called FILESTREAM[^]. It has little to do directly with the filestreams from .net for example. This feature enables you to have all pros of of storing files in the database, and the files you store are really managed by sql server (you have backup and so on), but they are not stored inside the database, but on the filesystem. And you have several ways to access them, there is even a share you can use if you want remote access. The major advantage of it is that you don''t need to put the huge load on the sql server that arises during such operations.
Of course, you have means to deal with them from c# too.
Please see following articles: How Do I: Use SQL File Stream[^]
http://blogs.microsoft.co.il/blogs/bursteg/archive/2008/05/12/ado-net-entity-framework-support-filestream.aspx[^]


这篇关于我们可以在Sql server 2008中存储文件(Word,Excel,Powerpoint,pdf)吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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