将图像上传到 SQL Server 2008
我看到 SQL Server 2008 有一个图像字段类型,我希望使用 VS 2010 FileUpload 控件 (c#) 让用户在我们的数据库上的个人资料旁边加载徽标,任何人都可以给我一个关于如何执行此操作的入门指南?
再次感谢
I see SQL Server 2008 has an image field type, I'm looking to use the VS 2010 FileUpload control (c#) to let users load a logo next to their profile on our database, can anyone give me a starter on how to do this?
thanks again
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
微软研究院有一篇非常好的论文,名为To Blob or Not To Blob 详细讨论了是否将实际数据存储在数据库表中,或者仅存储磁盘上文件的路径。
他们经过大量性能测试和分析后得出的结论是:
如果您的图片或文档大小通常低于 256K,则将它们存储在数据库 VARBINARY 列中效率更高
如果您的图片或文档大小通常超过 1 MB,将它们存储在文件系统中效率更高(并且使用 SQL Server 2008 的 FILESTREAM 属性,它们' 它们仍然处于事务控制之下并且是数据库的一部分)
在这两者之间,根据您的使用情况,有点难以抉择
如果如果您决定将图片放入 SQL Server 表中,我强烈建议您使用单独的表来存储这些图片 - 不要将员工照片存储在员工表中 - 将它们保存在单独的表中。这样,假设您并不总是需要选择员工照片作为查询的一部分,那么 Employee 表就可以保持精简、简洁且非常高效。
对于文件组,请查看文件和文件组体系结构了解简介。基本上,您可以从一开始就为大型数据结构创建具有单独文件组的数据库,或者稍后添加其他文件组。我们称之为“LARGE_DATA”。
现在,每当您要创建一个需要存储 VARCHAR(MAX) 或 VARBINARY(MAX) 列的新表时,您都可以为大数据指定此文件组:
查看有关文件组的 MSDN 介绍,并使用它!
There's a really good paper by Microsoft Research called To Blob or Not To Blob that discusses in great detail whether or not to store the actual data in your database table, or just a path to a file on disk.
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:
Check out the MSDN intro on filegroups, and play around with it!