将文件存储在SQL Server DB中 [英] Store a file in SQL Server DB

查看:76
本文介绍了将文件存储在SQL Server DB中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好



i希望将附录文件存储在sql server db的表中。

文件格式不同。

bmp,doc,jpg,ini,txt,doc和所有类型的文件。

我该怎么办?



谢谢

解决方案

您有五个选择:

1.始终将文件保存在文件系统中并仅存储路径在数据库中使用一些NVARCHAR数据。这种方法的问题是你的文件必须独立于数据库进行保护(否则它可以在数据库中列出时删除)。

2.使用BLOB(二进制大对象)存储使用VARBINARY数据类型的二进制格式的文件。此解决方案的问题是您可能需要一个非常大的存储空间,具体取决于您拥有的文档数量...

3.自SQL 2008起,就有FILESTREAM功能。此选项通过将文件系统用作数据库的扩展名来组合1和2。 http://msdn.microsoft.com/en-us/library/bb933993 (v = sql.100).aspx [ ^ ]

4. FileTables - 自SQL 2012以来 - 是FILESTREAM的扩展。这种技术将文件组合到表中,并允许通过API从简单的访问它们 - 没有数据库 - 像您访问文件系统的应用程序......

http://msdn.microsoft.com/en-us/library/ff929144(v = sql.110)的.aspx [ ^ ]

5. RBS(远程Blob存储)是FILESTREAM的扩展(也是自2012年以来),可以将文件存储在远程存储上而不是服务器上...... http://msdn.microsoft.com/en-us/library/gg638709(v = sql.110 ).aspx [ ^ ]


将它们保存在文件系统上,只保存在数据库中的路径。这样您就不需要将它们转换为bytearrays来保存。如果您必须这样做,请将它们转换为内存流,然后转换为字节数组并将它们保存在数据库中。在这种情况下,绝对必须将文件名(或至少文件TYPE)保存在单独的字段中。


请保存到根目录下的文件系统中。

如果要存储到数据库中请声明DB列varbinary类型。




http://msdn.microsoft.com/en-us/库/ ms187752.aspx

hello

i wants to store appendix file in a table in sql server db.
the format of files are diffrent.
bmp, doc, jpg, ini, txt, doc and all type of file.
how must i do it?

thanks

解决方案

You have five options:
1. Save the file as always in the file system and store only the path in the database using some NVARCHAR data. The problem of this method is that you file have to be secured independently from the DB (otherwise it can be deleted while still listed in the DB).
2. Use BLOB (Binary Large OBject) to store the file in binary format using VARBINARY data-type. The problem with this solution is you may need a very large storage, depending on the amount of the documents you have...
3. Since SQL 2008 there is the FILESTREAM feature. This option combines 1 and 2 by using the file system as na extension of the DB. http://msdn.microsoft.com/en-us/library/bb933993(v=sql.100).aspx[^]
4. FileTables - since SQL 2012 - are an extension of FILESTREAM. This technique combines files into tables and enables accessing them via an API from simple - no DB - applications like you access the file system...
http://msdn.microsoft.com/en-us/library/ff929144(v=sql.110).aspx[^]
5. RBS (Remote Blob Storage) is an extension of FILESTREAM (also since 2012) to enable to store the files on a remote storage instead on the server...http://msdn.microsoft.com/en-us/library/gg638709(v=sql.110).aspx[^]


Save them on file system and only their path in the database. That way you don't need to convert them to bytearrays to save. If you absolutely have to do it, convert them into memory streams then to byte arrays and save them in the database. In this case, it is absolutely imperative to save the file name (or at least file TYPE) in the separate field.


Please Save into File system in root directory .
if you want to store into Database Please declare DB column varbinary type.


http://msdn.microsoft.com/en-us/library/ms187752.aspx


这篇关于将文件存储在SQL Server DB中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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