Storing an image inside SQL DB

Storing an image inside SQL DB

Post by Xin L » Fri, 20 Jul 2001 09:28:48


Hi,

I am working on a database that contains some records that reference a
picture.  As things stand right now, the pictures are stored in a directory
somewhere on the server.  The DB records are pulled by some ASP code, and
the picture is displayed across the web.  I've noticed that SQL has an image
datatype, and I was wondering what would be the advantages to storing an
image in the DB as opposed to separately as a file, as well as the steps
need to store and retrieve the image across the web.  Thanks.

Xin Li

 
 
 

Storing an image inside SQL DB

Post by Michael Flemin » Fri, 20 Jul 2001 13:29:40


One advantage would be in terms of data management in that the images would
be backed up with the entire database if they are store within the database.

If you ever have the need to take copies of your database or need to
replicate it then you will be assured that the images will come with the
database and not need to worry about moving or copying a second data source.

Even if you do move the images separately within their file directory you
will have to make certain that any pointers to these images that you hold
within the database are updated if you change the actual location.

If you are going to access externally held images across the web then you
need to make certain that the physical files are on the correct side of any
fire walls to ensure that access will be allowed.  Storing the images within
the database gives the advantage of using the database level security.


Quote:> Hi,

> I am working on a database that contains some records that reference a
> picture.  As things stand right now, the pictures are stored in a
directory
> somewhere on the server.  The DB records are pulled by some ASP code, and
> the picture is displayed across the web.  I've noticed that SQL has an
image
> datatype, and I was wondering what would be the advantages to storing an
> image in the DB as opposed to separately as a file, as well as the steps
> need to store and retrieve the image across the web.  Thanks.

> Xin Li


 
 
 

Storing an image inside SQL DB

Post by OgiBoh » Fri, 20 Jul 2001 13:31:58


A wide spread practice of doing this is storing the files on the hard drive
and just the name of the file in the SQL Server (which is what you are doing
now). I guess it is a better way. The SQL Server stores the pictures to a
location on the hard drive and just a pointer in the database so there isn't
much difference either.


Quote:> Hi,

> I am working on a database that contains some records that reference a
> picture.  As things stand right now, the pictures are stored in a
directory
> somewhere on the server.  The DB records are pulled by some ASP code, and
> the picture is displayed across the web.  I've noticed that SQL has an
image
> datatype, and I was wondering what would be the advantages to storing an
> image in the DB as opposed to separately as a file, as well as the steps
> need to store and retrieve the image across the web.  Thanks.

> Xin Li

 
 
 

Storing an image inside SQL DB

Post by Greg Obleshchu » Fri, 20 Jul 2001 14:27:30


A suggestion would be "Don't do it".  Have a search through this News group
and you will find this question asked a lot.  The answer almost always comes
back as "Don't do it".  SQL server performance will be degraded.  IIS has
caching in-built,  which means that it will cache the pictures and certain
objects.  By placing them in a database you negate this cache, so every time
you want a 2MB picture you have to retrieve it from a database.  This
database is normally on a separate server to the public web server.  So you
have to transfer is across the internal network as well.  There is nothing
wrong with storing images and documents in a directory , that's what they
are there for, that's what they are good at.  DB are good at data storage
SQL DB are good at storing lots or records and retrieving them in different
orders.  Let each one do there job and you will be netter off.

regards
Greg O


Quote:> Hi,

> I am working on a database that contains some records that reference a
> picture.  As things stand right now, the pictures are stored in a
directory
> somewhere on the server.  The DB records are pulled by some ASP code, and
> the picture is displayed across the web.  I've noticed that SQL has an
image
> datatype, and I was wondering what would be the advantages to storing an
> image in the DB as opposed to separately as a file, as well as the steps
> need to store and retrieve the image across the web.  Thanks.

> Xin Li

 
 
 

Storing an image inside SQL DB

Post by Darren Brinksneade » Fri, 20 Jul 2001 22:43:18


One other thing to add to that...

When storing images on SQL Server in will store them as binary data like
this:

0x151C2F00020000000D000E0014002100...<more HEX
numbers>...FFFF9BFFFFFFFFFFFFFFFFE000000000000

Which doesn't look to pretty on a web page. You would have to use some type
of picture control on your page to render the binary data back into an
image.

As opposed to just doing an <IMG src="<urlpath or relative
path>/<imagename>.jpg">

--
Darren Brinksneader MCDBA, MCSE+I, CNE, CCA, MCT, CTT


> A suggestion would be "Don't do it".  Have a search through this News
group
> and you will find this question asked a lot.  The answer almost always
comes
> back as "Don't do it".  SQL server performance will be degraded.  IIS has
> caching in-built,  which means that it will cache the pictures and certain
> objects.  By placing them in a database you negate this cache, so every
time
> you want a 2MB picture you have to retrieve it from a database.  This
> database is normally on a separate server to the public web server.  So
you
> have to transfer is across the internal network as well.  There is nothing
> wrong with storing images and documents in a directory , that's what they
> are there for, that's what they are good at.  DB are good at data storage
> SQL DB are good at storing lots or records and retrieving them in
different
> orders.  Let each one do there job and you will be netter off.

> regards
> Greg O



> > Hi,

> > I am working on a database that contains some records that reference a
> > picture.  As things stand right now, the pictures are stored in a
> directory
> > somewhere on the server.  The DB records are pulled by some ASP code,
and
> > the picture is displayed across the web.  I've noticed that SQL has an
> image
> > datatype, and I was wondering what would be the advantages to storing an
> > image in the DB as opposed to separately as a file, as well as the steps
> > need to store and retrieve the image across the web.  Thanks.

> > Xin Li

 
 
 

Storing an image inside SQL DB

Post by Christopher Klei » Sun, 22 Jul 2001 02:54:32


We had the same issue, except our pictures were relatively small so it made
the performance issues a calculated acceptable factor.  A sample to get
things in/out of the db:
'-=-==-=-=--=--=-=-=-=-Upload the image to the webserver

Dim objUpload, lngLoop
FilePath="C:\INETPUB\WWWROOT\TEST\UPLOAD\"
If Request.TotalBytes > 0 Then
 Set objUpload = New Upload
 'For lngLoop = 0 to objUpload.Files.Count - 1
    'If accessing this page annonymously,
    'the internet guest account must have
    'write permission to the path below.
    objUpload.Files.Item(0).Save FilePath
 'Next
'-=--=-=--=-=-=-=-=- Insert image into Database
Dim dbImage
Dim rsImage
Dim mStream
strConnect="Provider=SQLOLEDB.1;Persist Security Info=False;User
ID=sa;password=;Initial Catalog=Test;Data Source=Knight"
set dbImage = server.createobject("adodb.connection")
set rsImage = server.CreateObject("adodb.recordset")
set mStream = server.CreateObject("adodb.stream")
dbImage.open(strConnect)
sqlstr="Select * from sketchinfos where intMasterAcctID=2"
rsImage.open sqlstr,dbImage,adOpenKeyset,adLockOptimistic
mStream.Type=adTypeBinary
mStream.Open
FileName=objUpload.Files.Item(0).FileName
mStream.LoadFromFile FilePath & FileName
rsImage.Fields("imgSketchJPG").Value=mStream.Read
rsImage.Update
rsImage.Close
dbImage.Close

Check out some ASP sites.  Mostly the biggest problem is that you need to
use a multi-part binary form to upload the information to where the database
can see it in the first place.

The other way you can get images into the database is via. the TEXTCOPY
utility.

Regards,

Christopher

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----

 
 
 

1. storing images inside sql server 7/2000 database

hi,

can anyone give me some tip on how to store images(jpeg & bmp) inside a
database using sql server 7/2000 with visual basic and the ado control.  or
just how to store images using vb and sql server 7/2000. any tip would be
greatly appreciated.  thank you

sicerely,
phong pham

2. XPATH question

3. store image, or image path in DB?

4. ORACLE running on a BSD VAX

5. Storing Images inside Pdox

6. pgsql-server/ /HISTORY rc/tools/pgindent/README

7. Storing Images Inside a Database

8. Stored Procedure as Recordsource for Update Query

9. Storing/Retrieving a GIF image from a SQL DB Table

10. store exe file inside the db

11. Determine then name of the DB inside a Stored Procedure

12. Image datatype, and storing images in SQL server

13. Store image by using image datatype in SQL 7.0