处理.NET IO流管理(在SQL Server中编码和存储)

发布于 2024-11-10 14:36:56 字数 207 浏览 2 评论 0原文

我想知道以下信息:

1)我需要,对于我的应用程序,处理IO流。特别是,我需要获取一个文件并将其分成几个二进制片段以在网络上发送。我可以使用 .NET API 执行此操作吗?

2)我还需要将这些片段保存在某个地方。我对将片段保存在数据库(SQL Server)中非常感兴趣。 SQL Server 是否提供特殊的表字段类型来保存二进制数据???

谢谢

I would like to know the following please:

1) I need, for an application of mine, to handle IO streams. In particular, I need to take a file and split it into several binary fragments to send on the network. Can I do this with .NET API?

2) I also need to save this fragments somewhere. I am really interested in saving fragments in a database (SQL Server). Does SQL Server provide special table field types for saving binary data???

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

勿忘初心 2024-11-17 14:36:56

1) 对于我的应用程序,我需要处理 IO 流。特别是,我需要获取一个文件并将其分成几个二进制片段以在网络上发送。我可以使用 .NET API 执行此操作吗?

是的。

2)我还需要将此片段保存在某处。我对将片段保存在数据库(SQL Server)中非常感兴趣。 SQL Server 是否提供特殊的表字段类型来保存二进制数据???

是的。

1) I need, for an application of mine, to handle IO streams. In particular, I need to take a file and split it into several binary fragments to send on the network. Can I do this with .NET API?

Yes.

2) I also need to save this fragments somewhere. I am really interested in saving fragments in a database (SQL Server). Does SQL Server provide special table field types for saving binary data???

Yes.

醉生梦死 2024-11-17 14:36:56

对于 SQL Server(版本 2005 或更高版本)中的二进制数据,请使用 VARBINARY 数据类型 - 请参阅 有关二进制和 varbinary 的 MSDN 文档 了解详细信息。

使用 VARBINARY(MAX) 数据类型,您可以在数据库表的列中存储最多 2 GB 的二进制数据。

正如微软研究院这篇非常好的论文,名为To Blob or Not To Blob 还表明,您不应该在 SQL Server 中过度存储二进制数据。

他们经过大量性能测试和分析后得出的结论是:

  • 如果您的图片或文档大小通常低于 256K,则将它们存储在数据库 VARBINARY 列中效率更高

  • 如果图片或文档大小通常超过 1 MB,将它们存储在文件系统中效率更高(并且使用 SQL Server 2008 的 FILESTREAM 属性,它们仍然处于事务控制之下并且是数据库的一部分)

  • ,根据您的使用情况,这有点难以抉择

如果您决定将图片放入 SQL Server 表中,我强烈建议使用单独的表来存储这些图片 - 不要将员工照片存储在员工表中- 将它们放在单独的表中。这样,假设您并不总是需要选择员工照片作为查询的一部分,那么 Employee 表就可以保持精简、简洁且非常高效。

对于文件组,请查看文件和文件组体系结构了解简介。基本上,您可以从一开始就为大型数据结构创建具有单独文件组的数据库,或者稍后添加其他文件组。我们称之为“LARGE_DATA”。

现在,每当您要创建一个需要存储 VARCHAR(MAX) 或 VARBINARY(MAX) 列的新表时,您都可以为大数据指定此文件组:

 CREATE TABLE dbo.YourTable
     (....... define the fields here ......)
     ON Data                   -- the basic "Data" filegroup for the regular data
     TEXTIMAGE_ON LARGE_DATA   -- the filegroup for large chunks of data

查看有关文件组的 MSDN 介绍,并使用它!

For binary data in SQL Server (in version 2005 or newer), use the VARBINARY datatype - see the MSDN docs on binary and varbinary for details.

With the VARBINARY(MAX) datatype, you can potentially store up to 2 GB of binary data in a column in your database table.

As this really good paper by Microsoft Research called To Blob or Not To Blob also shows, you shouldn't overdo your binary storage in SQL Server.

Their conclusion after a large number of performance tests and analysis is this:

  • if your pictures or document are typically below 256K in size, storing them in a database VARBINARY column is more efficient

  • if your pictures or document are typically over 1 MB in size, storing them in the filesystem is more efficient (and with SQL Server 2008's FILESTREAM attribute, they're still under transactional control and part of the database)

  • in between those two, it's a bit of a toss-up depending on your use

If you decide to put your pictures into a SQL Server table, I would strongly recommend using a separate table for storing those pictures - do not store the employee foto in the employee table - keep them in a separate table. That way, the Employee table can stay lean and mean and very efficient, assuming you don't always need to select the employee foto, too, as part of your queries.

For filegroups, check out Files and Filegroup Architecture for an intro. Basically, you would either create your database with a separate filegroup for large data structures right from the beginning, or add an additional filegroup later. Let's call it "LARGE_DATA".

Now, whenever you have a new table to create which needs to store VARCHAR(MAX) or VARBINARY(MAX) columns, you can specify this file group for the large data:

 CREATE TABLE dbo.YourTable
     (....... define the fields here ......)
     ON Data                   -- the basic "Data" filegroup for the regular data
     TEXTIMAGE_ON LARGE_DATA   -- the filegroup for large chunks of data

Check out the MSDN intro on filegroups, and play around with it!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文