在 WCF 中处理图像

发布于 2024-08-25 13:22:45 字数 278 浏览 0 评论 0原文

我有一个桌面应用程序,需要通过 TCP 协议向服务计算机上传/下载图像。

起初,我将图像存储在文件系统中,但我需要在 MS SQL DB 中比较哪种解决方案更好。图片数量超过五十万。我还不知道照片的大小是否有任何限制。

如果您曾经这样做过,请写下您对这个问题的看法。

哪一种更快、更安全?这么多照片,哪一个效果更好?如果我将存储在数据库上,我是否需要将图像与我用于应用程序的所有其他表分开存储,以及哪种类型效果更好 - 数据库上的图像或 varbinary?...等等。

谢谢。

I have a desktop application that needs to upload/download images to/from service computer over TCP Protocol.

At first, I stored images in file system, but I need to in MS SQL DB to compare which solution is better. Number of images is over half a million. I don't know yet will there be any limitation on size of a photo.

If you have done smth like that, please, write what your opinion upon this question.

Which one is faster, more safe? Which of them works better with this number of photos? If I'll store on DB, do I need to store images apart from all other tables which I use for my application and which type works better - image or varbinary on DB?..and so on.

Thank you.

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

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

发布评论

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

评论(2

滥情稳全场 2024-09-01 13:22:45

微软研究院有一篇非常好的论文,名为To Blob or Not To Blob< /a>.

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

  • 如果您的图片或文档大小通常低于 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 介绍,并使用它!

There's a really good paper by Microsoft Research called To Blob or Not To Blob.

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!

戏舞 2024-09-01 13:22:45

SQL Server 是哪个版本? 2008 版添加了专为此目的而设计的 FILESTREAM。 FILESTREAM 数据可以位于磁盘上,这使得访问速度非常快。

如果这不是一个选项,您可以考虑为图像数据创建一个单独的文件组(以便在对数据进行分区时提供最大的灵活性)并使用 varbinary(max) 或图像数据类型。

SQL 专家可能会提供更好的信息。

Which version of SQL server? Version 2008 adds FILESTREAM which is specifically designed for this purpose. FILESTREAM data can be located on disk which makes it very fast to access.

If this is not an option, you could look into creating a separate filegroup for your image data (to give you the most flexibility when partitioning your data) and use the varbinary(max) or image data types.

A SQL guru will probably chime in with better info.

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