Forum Moderators: open

Message Too Old, No Replies

Display image from access database

Display image from access database

         

pedrodepacos

5:56 am on Jun 10, 2003 (gmt 0)

10+ Year Member



I've looked everywhere and I haven't been able to find an example that shows how to display an image (in my case a jpg) that is stored in an access database.

I am using a dataset to get and display the information from access, but I need help with how to display the jpg.

Please help.

Woz

5:59 am on Jun 10, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi pedrodepacos, Welcome to WebmasterWorld.

Not a good idea to store the jpg in the database itself or you will very quickly suffer from database bloat. A better approack is to store the JPGs in a dedicated folder and then simply enter the filename in the database. Then you can call the filename from the database and code it the same as you would any image. Much Muih Much quicker.

Onya
Woz

pedrodepacos

6:23 am on Jun 10, 2003 (gmt 0)

10+ Year Member



I've read that there will be performance issues, but the dataset is kept in the application cache and is refreshed only every half hour, so it won't be actually making a call to the db everytime a page is loaded.

I may change my mind in the future, but I'd like to try it this way first, and I'm getting really frustrated that I can't find any examples that will show me how to do it. I've been searching for a few hours now and looked through all my ASP.NET and VB.NET manuals and can't find anything.

Woz

10:41 am on Jun 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am afraid I am not much help here as I have always just stored the path and not the whole blob. Hope you find what you are looking for.

Onya
Woz

ShawnR

10:51 am on Jun 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The TradeWinds example database that is included with MS Access is a pretty good reference. It doesn't show you how to do what you ask; but it does show how to do what Woz suggests.

Birdman

11:20 am on Jun 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This page explains it pretty well:

www.aspalliance.com/stevesmith/articles/imagequery.asp

dyates

7:14 am on Jul 20, 2003 (gmt 0)



You would want to enter the path to the image within your database.

strHTML = strHTML & "<img src=" & q& "images/" & rs("cimageurl") &q& " align=" & q& "left"& q & ">" & vbcrlf

This would much quicker and would not create database issues.

Let me know if you would like some sample code.

gangstah

12:36 pm on Jul 20, 2003 (gmt 0)

10+ Year Member



I would agree wholeheartedly with the suggestions of storing the URL rather than the image itself. It's so much easier and less space consuming.

TravelSite

12:45 pm on Jul 20, 2003 (gmt 0)

10+ Year Member



I've always stored the path - but there are times when it can be essential to store the actual image - e.g. if you start providing content to partners it can be essential for the images to be held in a database (especially if the images change a lot) - partners wouldn't be too keen on having to link to images on your site. I think it can also be useful for some admin stuff - easier to upload to database than setting access privileges for directories (at least with our hosting company!) - and perhaps more secure?.

pedrodepacos

4:55 pm on Jul 20, 2003 (gmt 0)

10+ Year Member



I really would have liked to store the actual image, but since I'm using an Access db, I really can't afford the performance hit. I've already designed the shopping cart script so that requests to the db are limited to the least number of times as possible. I cache several tables including the product table from the db as a dataset to alleviate the number of requests to the access db. Even though I'm caching the dataset, I'm sure that adding pictures will affect performance. If my clients ever do upgrade to SQL server then I will try to implement the images into the actual db.

TravelSite, what db are you using and what is your experience with performance using both methods?

TravelSite

7:10 pm on Jul 20, 2003 (gmt 0)

10+ Year Member



pedrodepacos,

we use MS SQL and have used Access in the past. The only method I've used is storing the pathname - simple for Access/SQL. I've looked into storing the images in an sql database but, on advice from our Database Developer, aren't doing this just yet. Her opinion is NOT to do it until you really need to. We won't really need to for another few months.

If there are good reasons to do it then I'd just say that, in my experience, a good server and sql can handle and process a LOT of data and cope with lots of traffic (and get feedback/help from your hosting company if possible). There's no harm in trying the method (let us know how you get on if you do it!).

If its for an admin related task then you may find some suitable scripts on the web that make uploading images to the webserver, and inserting the filename in a database, straightforward for clients. Again, if you get on with your hosting company they can help you with setting up access privilages so that clients can upload/delete from a directory.

pedrodepacos

8:15 pm on Jul 20, 2003 (gmt 0)

10+ Year Member



Good advice, TravelSite. Thanks for your response.

markus007

11:03 pm on Jul 21, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you get any kind of serious traffic, then you are totally screwed if you are serving images from a database.

pedrodepacos

6:57 am on Jul 22, 2003 (gmt 0)

10+ Year Member



Even if you were to use SQL Server?

aspdaddy

6:43 pm on Jul 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think you need to use something like:

response.binaryWrite objRS("binImage")

I would agree with everyone else and not store BLOBS in a database.

Another way is to just use the product key to name the images, then you dont need to store anything in the database :

Response.write "<img src=products/" & objRS("ID") & ".gif>"

<added>
Just found the info -
HOWTO: Display Images Stored in a BLOB Field [support.microsoft.com]
</added>

markus007

9:14 pm on Jul 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Even if you use SQL server.. Images where never ment to be stuck in a database, you get insane amounts of overhead, your database ram usage is going to skyrocket and the system will be slow.

pedrodepacos

10:57 pm on Jul 22, 2003 (gmt 0)

10+ Year Member



Thanks for the input, 007.

pff_iy

8:24 am on Jul 23, 2003 (gmt 0)

10+ Year Member



Why store the image in a database?
It would be much faster (performance) if you store the image path and dedicate a folder for the images.

Don't forget that it is very unefficient and your database will grow rapidly depending on the amount of images.

However if you really want to do this try this site it shows how to add a binary image to a database

[stardeveloper.com...]

DustSmoke

10:50 pm on Jul 25, 2003 (gmt 0)



pedrodepacos

Here;

[stardeveloper.com...]