Image save in database

那年仲夏 提交于 2019-12-13 10:44:44

问题


I want to save an uploaded image to database. Now my question is:

  1. What should be the data type for SQL Server 2000 for image? a. image b. varbinary

  2. what is the code for saving image in database?

  3. How to retrieve the image from database and show?

Please refer me any tutorial or guidline. Or if you can please share with me.

Thanks in advance.


回答1:


The data type should be text because the best way to save an image to a database is to save its path. Let your OS do the job of storing the actual files.




回答2:


Typically on SQL Server, you would use a BLOB, Binary Large OBject, to store images. We used it for Word documents on a previous project, and it worked just fine. See this article on Database Journal for more info, although a quick Google for the BLOB type will throw up lots more examples.




回答3:


I wrote this article a while back on this subject. It should help you with #2 and #3. It uses MySQL, but the basics are the same, you just need to replace the MySQL calls with the MSSQL calls.

As to #1, I would go with the obvious choice: "image".
I am not 100% sure of the differences between the two, however. It just seems obvious :)

Edit, according to this, it appears that the image datatype is deprecated. It will be removed in future versions. Not sure how much this affects you, seeing as you are using a 10 year old version, but it is worth keeping in mind.




回答4:


In SQLServer IMAGE or VARBINARY are allmost the same. IMAGE is 2GB but VARBINARY() needs a length argument. It's not good idea to store images in a database, the size increases a lot, with each Backup you need to save all images, with increasing size also increases the time to perform a Backup and Restore. You also need to change the network packet size (at the server properties, advanced, network, network packet size) In recents SQLServer versions the most adecuate datatype is varbinary(MAX)



来源:https://stackoverflow.com/questions/2552239/image-save-in-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!