473,748 Members | 2,471 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

to store or not to store an image

Hello all!

I am amazed how many posts I have read to store an image in SQL, and just as
many against it. So I learned how to store an image in a SQL db and retrieve
the image. A little tricky, but not too bad. But then I thought I wanted to
try the other way, by putting the file location in SQL and storing the actual
image in another directory.
I plan to have many images on my web application, up to as many as 5000.
Not to mention the other tables I will have, that will have just as many
records.
So I think I will go the old fasion route, and just put in the path in the
DB instead of the image.

Do I dare ask? What do you think is the best way to go?

Second thing is, I have found a ton of articles on how to store the image,
but can't find any that shows an example of just storing the file path. If
somebody would have an example of this, or point me in a direction, that
would be great!

Thanks for all your help!!!

Rudy
Nov 19 '05 #1
6 1917
Rudy - the problem with storing the images is that you don't know for sure
how big the thing could grow in most instance. Today 5,000 - tomorrow maybe
it turns into 10,000. It's a lot easier to buy network storage than to
accomodate the cahnge in the databse. + you can't use indexes on blob
fields. If you have 5,000 images, then I would avoid using Blobs - having
done it in the past. Let me put it this way - the benefit of being 'right'
about storing in the db is virtually indistinguishab le from the benefit of a
network drive - at least as far as the end user goes. The cost of being
wrong about the db is very very high. So there's basically a lot of risk
for a very little upside. IMHO, the math doesn't add up. The exception is
cases where you absolutely don't want the images exposed to end users except
through your application and you store them in the db and then have an a33
load of security on the db. I did this at my former job w/ about 10,000
pdfs, peformance totally sucked but the images were confidential and were
accessed rarely - one thing I forgot to mention above is the frequency of
access. The less they are accessed, teh less of a risk with storing in the
db.

I'd definitely ask my DBA for his/her opinion on the subject too - mine
would probably say no way without a really compelling argument.

As far as storing paths goes, just store the path as a varchar and then use
a ExectueScalar command or fill a datatable and use either the File or
FileInfo class passing in the value to get the file reference.

--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Rudy" <Ru**@discussio ns.microsoft.co m> wrote in message
news:77******** *************** ***********@mic rosoft.com...
Hello all!

I am amazed how many posts I have read to store an image in SQL, and just as many against it. So I learned how to store an image in a SQL db and retrieve the image. A little tricky, but not too bad. But then I thought I wanted to try the other way, by putting the file location in SQL and storing the actual image in another directory.
I plan to have many images on my web application, up to as many as 5000.
Not to mention the other tables I will have, that will have just as many
records.
So I think I will go the old fasion route, and just put in the path in the
DB instead of the image.

Do I dare ask? What do you think is the best way to go?

Second thing is, I have found a ton of articles on how to store the image,
but can't find any that shows an example of just storing the file path. If somebody would have an example of this, or point me in a direction, that
would be great!

Thanks for all your help!!!

Rudy

Nov 19 '05 #2
In addition to the variables W.G. Ryan mentioned, the size of the images is
also a factor in determining which technique is more performant.
In most cases I prefer saving to the DB, and the reasons are outlined in
this article:
http://SteveOrr.net/articles/EasyUploads.aspx

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Rudy" <Ru**@discussio ns.microsoft.co m> wrote in message
news:77******** *************** ***********@mic rosoft.com...
Hello all!

I am amazed how many posts I have read to store an image in SQL, and just
as
many against it. So I learned how to store an image in a SQL db and
retrieve
the image. A little tricky, but not too bad. But then I thought I wanted
to
try the other way, by putting the file location in SQL and storing the
actual
image in another directory.
I plan to have many images on my web application, up to as many as 5000.
Not to mention the other tables I will have, that will have just as many
records.
So I think I will go the old fasion route, and just put in the path in the
DB instead of the image.

Do I dare ask? What do you think is the best way to go?

Second thing is, I have found a ton of articles on how to store the image,
but can't find any that shows an example of just storing the file path.
If
somebody would have an example of this, or point me in a direction, that
would be great!

Thanks for all your help!!!

Rudy

Nov 19 '05 #3
> Do I dare ask? What do you think is the best way to go?

In terms of performance, storing images in a database is a huge waste of
resources. Why? Because the file system is a database. And a database app
such as SQL Server uses the file system to store its data. So, let's take a
look at the flow when using a database and when not using a database:

File System Only:

1. File is fetched from file system.

Database

1. Network Connection is made to database
2. Query is sent to database
3. Database parses query.
4. Database file is fetched from file system.
5. Image is retrieved from database file
6. Network Connection is closed
--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.

"Rudy" <Ru**@discussio ns.microsoft.co m> wrote in message
news:77******** *************** ***********@mic rosoft.com...
Hello all!

I am amazed how many posts I have read to store an image in SQL, and just
as
many against it. So I learned how to store an image in a SQL db and
retrieve
the image. A little tricky, but not too bad. But then I thought I wanted
to
try the other way, by putting the file location in SQL and storing the
actual
image in another directory.
I plan to have many images on my web application, up to as many as 5000.
Not to mention the other tables I will have, that will have just as many
records.
So I think I will go the old fasion route, and just put in the path in the
DB instead of the image.

Do I dare ask? What do you think is the best way to go?

Second thing is, I have found a ton of articles on how to store the image,
but can't find any that shows an example of just storing the file path.
If
somebody would have an example of this, or point me in a direction, that
would be great!

Thanks for all your help!!!

Rudy

Nov 19 '05 #4


"Kevin Spencer" wrote:
Do I dare ask? What do you think is the best way to go?


In terms of performance, storing images in a database is a huge waste of
resources. Why? Because the file system is a database. And a database app
such as SQL Server uses the file system to store its data. So, let's take a
look at the flow when using a database and when not using a database:

File System Only:

1. File is fetched from file system.

Database

1. Network Connection is made to database
2. Query is sent to database
3. Database parses query.
4. Database file is fetched from file system.
5. Image is retrieved from database file
6. Network Connection is closed
--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.

"Rudy" <Ru**@discussio ns.microsoft.co m> wrote in message
news:77******** *************** ***********@mic rosoft.com...
Hello all!

I am amazed how many posts I have read to store an image in SQL, and just
as
many against it. So I learned how to store an image in a SQL db and
retrieve
the image. A little tricky, but not too bad. But then I thought I wanted
to
try the other way, by putting the file location in SQL and storing the
actual
image in another directory.
I plan to have many images on my web application, up to as many as 5000.
Not to mention the other tables I will have, that will have just as many
records.
So I think I will go the old fasion route, and just put in the path in the
DB instead of the image.

Do I dare ask? What do you think is the best way to go?

Second thing is, I have found a ton of articles on how to store the image,
but can't find any that shows an example of just storing the file path.
If
somebody would have an example of this, or point me in a direction, that
would be great!

Thanks for all your help!!!

Rudy


Nov 19 '05 #5
Hello all!

Thank you for the great response. WG, I'm with you. Coming from the
hardware side, my thought is if I get too deep, and found the DB solution
didn't work for me, it would be tough to get out. Access is also a huge
thing. Theese images will be accessed a great deal, so I know there is going
to be alot of traffic.

Steve, I read your atricle. As a matter of fact, that was the article I used
to learn how to store and retrieve images on the DB. Nice job, laid out very
nicely. The reason I was trying the image in the DB way, beacuse I was going
to have my website put up on the webfarm for a few months, until I have
enough revenue to set buy the servers and hardware to run out of my office.
I didn't want some guy at this place snooping aroundand looking at the
images. I could have the images stiored at my location, and still have SQL at
the web farm, but it seems clunky that way.

But now I think go into debt big, buy the hardware and run it out of my
location. So I think in my case, storing the file path is the way to go. the
oterway seems fine for security and low access, but for high access it just
seems easier to do it the other way.

Thanks again for all your time.

Rudy

"Kevin Spencer" wrote:
Do I dare ask? What do you think is the best way to go?


In terms of performance, storing images in a database is a huge waste of
resources. Why? Because the file system is a database. And a database app
such as SQL Server uses the file system to store its data. So, let's take a
look at the flow when using a database and when not using a database:

File System Only:

1. File is fetched from file system.

Database

1. Network Connection is made to database
2. Query is sent to database
3. Database parses query.
4. Database file is fetched from file system.
5. Image is retrieved from database file
6. Network Connection is closed
--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.

"Rudy" <Ru**@discussio ns.microsoft.co m> wrote in message
news:77******** *************** ***********@mic rosoft.com...
Hello all!

I am amazed how many posts I have read to store an image in SQL, and just
as
many against it. So I learned how to store an image in a SQL db and
retrieve
the image. A little tricky, but not too bad. But then I thought I wanted
to
try the other way, by putting the file location in SQL and storing the
actual
image in another directory.
I plan to have many images on my web application, up to as many as 5000.
Not to mention the other tables I will have, that will have just as many
records.
So I think I will go the old fasion route, and just put in the path in the
DB instead of the image.

Do I dare ask? What do you think is the best way to go?

Second thing is, I have found a ton of articles on how to store the image,
but can't find any that shows an example of just storing the file path.
If
somebody would have an example of this, or point me in a direction, that
would be great!

Thanks for all your help!!!

Rudy


Nov 19 '05 #6
Hi W.G.

Could you please give me an example how you would use the file info class. I
would save the pics to something like c:mypics. How would I get the pic name
and so forth. Or if you know of a place that shows this. That would be
great!!!

Thanks for your help!!!

Rudy

"W.G. Ryan eMVP" wrote:
Rudy - the problem with storing the images is that you don't know for sure
how big the thing could grow in most instance. Today 5,000 - tomorrow maybe
it turns into 10,000. It's a lot easier to buy network storage than to
accomodate the cahnge in the databse. + you can't use indexes on blob
fields. If you have 5,000 images, then I would avoid using Blobs - having
done it in the past. Let me put it this way - the benefit of being 'right'
about storing in the db is virtually indistinguishab le from the benefit of a
network drive - at least as far as the end user goes. The cost of being
wrong about the db is very very high. So there's basically a lot of risk
for a very little upside. IMHO, the math doesn't add up. The exception is
cases where you absolutely don't want the images exposed to end users except
through your application and you store them in the db and then have an a33
load of security on the db. I did this at my former job w/ about 10,000
pdfs, peformance totally sucked but the images were confidential and were
accessed rarely - one thing I forgot to mention above is the frequency of
access. The less they are accessed, teh less of a risk with storing in the
db.

I'd definitely ask my DBA for his/her opinion on the subject too - mine
would probably say no way without a really compelling argument.

As far as storing paths goes, just store the path as a varchar and then use
a ExectueScalar command or fill a datatable and use either the File or
FileInfo class passing in the value to get the file reference.

--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Rudy" <Ru**@discussio ns.microsoft.co m> wrote in message
news:77******** *************** ***********@mic rosoft.com...
Hello all!

I am amazed how many posts I have read to store an image in SQL, and just

as
many against it. So I learned how to store an image in a SQL db and

retrieve
the image. A little tricky, but not too bad. But then I thought I wanted

to
try the other way, by putting the file location in SQL and storing the

actual
image in another directory.
I plan to have many images on my web application, up to as many as 5000.
Not to mention the other tables I will have, that will have just as many
records.
So I think I will go the old fasion route, and just put in the path in the
DB instead of the image.

Do I dare ask? What do you think is the best way to go?

Second thing is, I have found a ton of articles on how to store the image,
but can't find any that shows an example of just storing the file path.

If
somebody would have an example of this, or point me in a direction, that
would be great!

Thanks for all your help!!!

Rudy


Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
13388
by: Karen Grube | last post by:
Hi! Each week, we receive a two-page PDF file from UPS along with a separate flat file (a CSV) The PDF file contains the overview of our weekly invoice and the CSV contains the details of each shipment. I download the file from UPS and then use DTS to import the data into SQL. At that point, I have a Crystal report that prints what looks like a regular UPS invoice. The only problem is that I wind up with having to print two...
10
26194
by: Raghavendra RAV | last post by:
Hi, I need to store an image from a Graphics object(.NET) inside a xml data island. Anyone might have came accross or have an idea how to do this. Please share. Thanks & Regards, Raghu, CSS India +91 98402 56561
5
10633
by: moondaddy | last post by:
I'm caching a dataset in an asp.net session variable to hold a user's data. one data item I need to store is an image the user uploaded. My problem is that I don't know how to get the image into the dataset because I don't know what datatype to set the dataset column and then set this image to. I saw an example where someone defended a datatable in the global class and defined the column as an object, however, when I define a strongly...
4
3009
by: serge | last post by:
I was working on figuring out where a certain application was storing the multiple selection choices I was doing through the app. I finally figured out that they were being store in an IMAGE data type colum with the variable length of 26 bytes. This is the first time I ran into such way of storing multiple selections in a single Image data type. Is this a better alternative than to store into a One-to-Many tables? If so then I'll have...
1
6658
by: nwebhosting | last post by:
Hello and thank you. Could you please help me with this.: i try to store images using the following code, and it just bring a blank screen. i being trying different things and i am not sure if the problem is on values. Please help me. PUT YOUR CODE WITHIN code OR php TAGS NEXT TIME!!!! <body> <form action="insert2.php"method="post" enctype="multipart/form-data">
0
1824
by: wizardworkz | last post by:
Hello All! Having a bit of a problem combining php with javascript here. What I have is a store with images (There will be a smaller image of each item, and a larger image of each item, but I want users to click on a link under the image shown (Smaller image) for a popup window showing a larger image. I have already setup an additional table line named "image2" and want the image be puleed from the db (images folder) to pop up to a window...
0
2760
by: Skiran | last post by:
Hi to everybody, I am handling a large-scale project of MIS (Marketing information System). I am using Vb 6 as front end, Ms Access as back end and Crystal report 8 as reporting tool. 1) In the project i am required to save customers image to database, and it should be shown in individual’s customers report also. I had taken OLE field in the database to save the images. I had taken Common dialog box control to select image and
0
1725
by: harshad | last post by:
Dear All,Here I am facing problem to store image.I am trying to store byte array(image) in to session variable so at time of update I will got that byte array and I do my update. here i am given following code so kindly help out me. on Button Click Event--------------------------------- Private Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click Try ' Dim fileUpload1 As FileUpload =...
6
5095
by: Keith Hughitt | last post by:
Hi all, I've run into a strange error while trying to store some PNG images in a MySQL database using MySQLdb. When I try to insert smaller images (< 64kb or so) everything seems to work fine. When I start trying to insert larger images (~150kb), however, the images get corrupted along the way. The result is that only part of the image, e.g. the top 30% of the image, is stored in the database, and the rest is simply transparent.
0
8823
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9530
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9363
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9238
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8237
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.