Storing pictures in a database

mike55

Well-known member
Joined
Mar 26, 2004
Messages
726
Location
Ireland
Hi

I was wondering what is the most of effective way for storing pictures in a database. One option that I was considering was, simple save the picture to a folder on the localmachine and then add the path to that picture into the database field. Otherwise, would it be more effective to use the datatype image in the database table.

Any other suggestions??

Mike55
 
Are these images that would be used on multiple machines? If so it doesnt make sense to store it in a folder on one machine so I would store it in the database. Also, what database?
 
As Machaira asked, what type of DB-Server?

All of them are useing a differend syntax.
 
Most often, it is more efficient to store the path in the database. I notice that you said data type image, that sounds like MS SQL. Image is still just binary data. When you store images or binary data in a database, you have to convert it back to something that can be more useful. This is either done by creating a temporary file or memory stream to recreate the file from its binary form in the database. If you just store the path in the database, you cut out that step.

If you are using MS Access as the backend, then storing the picture is highly unrecommended because of the 2GB Max size.

With any database though, not just Access, storing binary data (images, or whatever) can cause severe database bloat. However, sometimes this is unavoidable and the binary data must be stored in the database.


Chester
 
Will be using SQL Server 2000. I recon that it would be in my best interest to simple store a file path for the image in the database so as to reduce database size.

Mike55.
 
mike55 said:
I was wondering what is the most of effective way for storing pictures in a database. One option that I was considering was, simple save the picture to a folder on the localmachine and then add the path to that picture into the database field. Otherwise, would it be more effective to use the datatype image in the database table.

Yes, you have 2 ways:
- store the image path
- store the byte array in a memo (or blob depending on the DBMS) that you can retrieve with
C#:
                    Bitmap bmp = new Bitmap(_image);
                    TypeConverter bmpc = TypeDescriptor.GetConverter(bmp.GetType());
                    return (byte[])bmpc.ConvertTo(bmp, typeof(byte[]));

With "old" tecnologies you colud also store the image as OLE-resource, but I deprecate it.
 
Unless youre worried about people linking to your images on there web site its really not a great option to store images in a BLOB field as other have mentioned. I can think of some reasons not to, but nothing that is under normal circumstances.
 
Back
Top