Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2007
    Posts
    3

    Unanswered: How do I store images (like GIFs) in sql server 2005?

    I have a web server running fine together with an sql 2005 db. I use asp as my web server programming language and want to be able to display images that are stored in the database.

    My question of course is how do I put images, for example an image called "image1.gif" into the database?

    After having stored the images in the db, I guess that the are displayed on my web pages the same way as all text information (by writing something like <%=rs("image_column")%> ).... Anyway first I need help with how to store imgs in the database...

  2. #2
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    you can do this but I am old fashioned and I do not. I store the network location, directory and file name in 3 seperate fields.
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  3. #3
    Join Date
    May 2004
    Location
    Seattle
    Posts
    1,313
    First of all, I would recommend you not do this. It's usually preferred to store the path to the file in sql server, and store the file itself on the file system. sql server is for storing relational data, not files. the file system is better at storing files.

    But if you insist on it, have a look at the yellow highlighted articles and posts at this link:

    http://www.sqlteam.com/forums/topic....s=Image,Images

  4. #4
    Join Date
    Jan 2007
    Posts
    3
    Thank you for your answers. Just want to make sure that I haven't misunderstood anytihing since I am new to this program.

    So what you mean is that I should store something like "c:\inetpub\wwwroot\images\MyImage.gif" (links to the images on the server's hard drive) in the table instead of the images themselves?

  5. #5
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    Just one note: if you plan to store several thousand pictures you will have to make sure not to store them all in a single directory. Most file systems (Linux or Windows) don't really like huge directories.

    I am maintaining an application where we decided against the storage in the database and now the directory with all the files has grown to over 25.000 files.
    This is really hard to handle with e.g. an FTP program.

    If you expect that many files, do think either about a directory structure where you store not more than say a hundred files in a directory, or put them into the database (do not underestimate the problems with handling large directories for e.g. backups etc)

  6. #6
    Join Date
    May 2004
    Location
    Seattle
    Posts
    1,313
    Quote Originally Posted by Pendymi
    Thank you for your answers. Just want to make sure that I haven't misunderstood anytihing since I am new to this program.

    So what you mean is that I should store something like "c:\inetpub\wwwroot\images\MyImage.gif" (links to the images on the server's hard drive) in the table instead of the images themselves?
    basically yes.

    what Thrasymachus was suggesting is that you store the path as three columns, like this:

    root varchar(50),
    directory varchar(200),
    file varchar(50)

    where in your example, the first row would contain the values in these fields:

    c:\, inetpub\wwwroot\images\, MyImage.gif

    that way, you can easily move images around on the disk or to a different network share and the updates to your table won't be too messy.

  7. #7
    Join Date
    Jan 2007
    Posts
    3
    Ok,

    Thanks again for your answer...

Posting Permissions

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