Results 1 to 16 of 16

Thread: Loading Images from Database, the Best Practice

  1. #1

    Thread Starter
    Hyperactive Member oyad's Avatar
    Join Date
    Feb 2003
    Location
    PhoxWare MicroSystems
    Posts
    463

    Loading Images from Database, the Best Practice

    hi, any tip on how best to work with database images?
    i need to display images on each page in my application, the images are stored in the database.Going to the database on each page hit for a data fetch will not make this application scalable. how best can i work around this. the images depends on each unique user (session) using the application, so i cant cache this data. note, how to fetch is not the issue but implementing sometime more scalable along with less resources (database access, CPU , server memory etc)


    any tips?thanx
    Nobody is smarter than all of us!

  2. #2
    Hyperactive Member Greyskull's Avatar
    Join Date
    Dec 2003
    Location
    somewhere in England
    Posts
    382

    Re: Loading Images from Database, the Best Practice

    Have you got the actual image stored in your database or just image file names?

    Coz I have always placed filenames on the database then just pull out in the front-end using asp.
    Please go to the Thread Tools menu and click Mark Thread Resolved when your post is answered
    If someone helped you today then please consider rating their post.

  3. #3
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Loading Images from Database, the Best Practice

    Hey,

    Agreed. I tend to always store just the image location in the database, and then actually store the image on the file system.

    However, this doesn't actually answer your question, as you would still have to render the image from the file system to the client.

    One way to ensure optimal performance might be to Cache the image. Are you familiar with this concept?

    Gary

  4. #4

    Thread Starter
    Hyperactive Member oyad's Avatar
    Join Date
    Feb 2003
    Location
    PhoxWare MicroSystems
    Posts
    463

    Re: Loading Images from Database, the Best Practice

    Quote Originally Posted by Greyskull View Post
    Have you got the actual image stored in your database or just image file names?

    Coz I have always placed filenames on the database then just pull out in the front-end using asp.
    the actually images files resides in a database, i fetch them & at runtime ,re-create them as jpeg but problem is : i dont want to keep doing this on each page hit
    Nobody is smarter than all of us!

  5. #5
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Loading Images from Database, the Best Practice

    Hey,

    In that case, I think the only option would be to Cache the picture.

    Or, re-design your application to not store the image in the database.

    How big are these images?

    Gary

  6. #6

    Thread Starter
    Hyperactive Member oyad's Avatar
    Join Date
    Feb 2003
    Location
    PhoxWare MicroSystems
    Posts
    463

    Re: Loading Images from Database, the Best Practice

    Quote Originally Posted by gep13 View Post
    Hey,

    In that case, I think the only option would be to Cache the picture.

    Or, re-design your application to not store the image in the database.

    How big are these images?

    Gary
    The images are around 100kb each and about 10 of these images is shown on each page. can i cache uniquely for each user using a user control?(VaryByParam)
    Nobody is smarter than all of us!

  7. #7
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Loading Images from Database, the Best Practice

    Hey,

    You can if you need to.

    http://msdn.microsoft.com/en-us/library/ms972379.aspx

    Can you provide some details as to what exactly you are trying to achieve?

    Gary

  8. #8

    Thread Starter
    Hyperactive Member oyad's Avatar
    Join Date
    Feb 2003
    Location
    PhoxWare MicroSystems
    Posts
    463

    Re: Loading Images from Database, the Best Practice

    Quote Originally Posted by gep13 View Post
    Hey,

    You can if you need to.

    http://msdn.microsoft.com/en-us/library/ms972379.aspx

    Can you provide some details as to what exactly you are trying to achieve?

    Gary
    on each page hit, am fetching images from the database & displaying these images on the web pages. Am sure this method is not scalable (becuase of the datbase fetch on each page hit), so am looking at caching the data so as to go to the database once and only once & re-use the images in the subsequent pages without reverting to the database again for an image fetch. Note, images to be fetch from the database are unique for each user using the application
    Nobody is smarter than all of us!

  9. #9
    Hyperactive Member Greyskull's Avatar
    Join Date
    Dec 2003
    Location
    somewhere in England
    Posts
    382

    Re: Loading Images from Database, the Best Practice

    If you have the images as filenames and stored the images in a local folder you could simply call the Eval function to pull each image through i.e.

    Eval("PicURL","images\\thumb_{0}");

    But since you have them in your actual db, I read an article before on how to pull them out although not sure how effective it is as I haven't tried it personally.

    http://www.sqlteam.com/article/images-and-sql-server

    Regards
    Please go to the Thread Tools menu and click Mark Thread Resolved when your post is answered
    If someone helped you today then please consider rating their post.

  10. #10
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Loading Images from Database, the Best Practice

    Hey,

    If I were doing your application, then I would definitely look at storing the files on the file system, and just the location in the database, this should make it more scalable. Having said that though, at the end of the day, enterprise databases should eat this type of thing up for lunch.

    As a complete example, take a look at this Starter Kit:

    http://www.asp.net/downloads/starter-kits/personal/

    Gary

  11. #11

    Thread Starter
    Hyperactive Member oyad's Avatar
    Join Date
    Feb 2003
    Location
    PhoxWare MicroSystems
    Posts
    463

    Re: Loading Images from Database, the Best Practice

    Quote Originally Posted by Greyskull View Post
    If you have the images as filenames and stored the images in a local folder you could simply call the Eval function to pull each image through i.e.

    Eval("PicURL","images\\thumb_{0}");

    But since you have them in your actual db, I read an article before on how to pull them out although not sure how effective it is as I haven't tried it personally.

    http://www.sqlteam.com/article/images-and-sql-server

    Regards
    thanx so much for ur replies
    they are all good and interesting

    what am currently working on, am not working with the file system, just between my code and the database. how retrieve the images from the database is not an issue but my problem is how best to use less resources. i need to display the images from database in each page. i dont want to get down to the database on each page hit becuase that will mean : if the user visits 20 pages, i get down to the database 20 times!, to resolve this, am looking at the asp.net cache stuff and also trying to see if there is also another alternative method to this
    Nobody is smarter than all of us!

  12. #12
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Loading Images from Database, the Best Practice

    Hey,

    In this case, I would have said Cache would have been your best option.

    Gary

  13. #13

    Thread Starter
    Hyperactive Member oyad's Avatar
    Join Date
    Feb 2003
    Location
    PhoxWare MicroSystems
    Posts
    463

    Re: Loading Images from Database, the Best Practice

    Quote Originally Posted by gep13 View Post
    Hey,

    In this case, I would have said Cache would have been your best option.

    Gary
    i'd implemented the intended functionality as a user control and cached the user control by setting the below in the user control
    <%@ OutputCache Duration ="3600" VaryByControl="onlineUser" Shared ="true" %>

    but am running into some issues, the same content of user control is displayed for all users, i needed to cache on a individual user basis. plz , am i missing out any setting?
    Nobody is smarter than all of us!

  14. #14

  15. #15
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Loading Images from Database, the Best Practice

    Gun, meet foot.

    If you're worried about performance, your first step should be to remove the images from the database and leaving them on disk. With caching, you're increasing load on the server since you're now storing the images in memory, on average 1MB per page - that is quite a lot, especially if you're in a shared hosting environment, but a lot even if it's a dedicated server. I don't believe that caching is a good idea though, it's not a solution but a workaround to a design flaw. You are correct that it is not scalable and in the long term, it can cause more problems than the current convenience is worth. With storing the files on disk, you prevent future database bloat and you don't have that extra step of conversion and handling.

    If however, you insist on continuing this way, you want data caching (adding items to the Cache object using Cache.Insert, etc).

  16. #16

    Thread Starter
    Hyperactive Member oyad's Avatar
    Join Date
    Feb 2003
    Location
    PhoxWare MicroSystems
    Posts
    463

    Re: Loading Images from Database, the Best Practice

    Quote Originally Posted by mendhak View Post
    Gun, meet foot.

    If you're worried about performance, your first step should be to remove the images from the database and leaving them on disk. With caching, you're increasing load on the server since you're now storing the images in memory, on average 1MB per page - that is quite a lot, especially if you're in a shared hosting environment, but a lot even if it's a dedicated server. I don't believe that caching is a good idea though, it's not a solution but a workaround to a design flaw. You are correct that it is not scalable and in the long term, it can cause more problems than the current convenience is worth. With storing the files on disk, you prevent future database bloat and you don't have that extra step of conversion and handling.

    If however, you insist on continuing this way, you want data caching (adding items to the Cache object using Cache.Insert, etc).
    thanx so much. you are very correct and in fact,i'd switched back to using the filesystem for the images (i couldnt initially because WRITE access ). So, am getting back to my desk to continue with the application
    Nobody is smarter than all of us!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width