Loans - Mortgage - Myspace Layouts - MPAA - Loans

PDA

View Full Version : VB-SQL SERVER Question


vijaykoul
Feb 14th 2005, 1:00 am
hi,

i want to upload the images into the SQL SERVER database
using VB. I want images to be stored in the database and not
the path of the images.
how can i do it

J.D.
Feb 14th 2005, 8:01 am
i want to upload the images into the SQL SERVER database
using VB. I want images to be stored in the database and not
the path of the images.
how can i do itI can't help you with VB, but speaking of SQL Server, you would need to store your images in a column defined as image. This datatype allows you to store up to 2 GB of data.

Keep in mind that storing images in the database will require additional maintenance on your part and will also put additional strain on your web server. For example, you will have to retrieve images from the DB first and then serve them with some custom HTTP headers (e.g. content-type). This may also prevent your web server from being able to use file compression, depending on your configuration.

J.D.

daboss
Feb 14th 2005, 8:10 am
i'm assuming your means visual basic instead of vbulletin :)

the best way to do this is to use the stream object provided by ADO:
1. instantiate a new stream object - e.g. set obj = new adodb.stream
2. set the stream object's type to binary
3. load an image from disk into the stream using the loadfromfile method of the stream object
4. assign the image in the stream object into a sql server recordset and save or update the recordset

i'd use a blob datatype in sql server to save the image. there's also an image data type but i've never used it before.

personally, i prefer to save the images to directories on the file system and only save the file path to sql server... but that's my personal preference...

J.D.
Feb 14th 2005, 8:23 am
i'd use a blob datatype in sql server to save the image. there's also an image data type but i've never used it before.BLOB's are stored as image, text or ntext.

J.D.

mopacfan
Feb 14th 2005, 8:35 am
The big question is WHY???!!!!

J.D.
Feb 14th 2005, 8:45 am
The big question is WHY???!!!!If your question is about my last comment, there's no such data type as BLOB in SQL Server. Binary large objects (BLOBs) may be stored in columns defined as image, text or ntext. image doesn't actually mean that it has to be a picture - it can be any binary data (usually greater than 8K - smaller data should be stored in a varbinary column).

J.D.

mopacfan
Feb 14th 2005, 8:50 am
No JD, I mean why store images in the database. It produces a great deal of overhead, the images cannot be delievered to the browser efficiently and it's just a bad idea all the way around.

vijaykoul
Feb 14th 2005, 12:42 pm
i do not want to use the above posted question for web browsers. this problem i am facing while developing software for a cosmetics company and saving the path is not a good idea.
that is why i want to upload image using VB into SQL SERVER
no scripting language is used

J.D.
Feb 14th 2005, 1:22 pm
i do not want to use the above posted question for web browsers. I'm not sure what you mean. Are you saying that these images won't be served by a web server, but instead you will use some client-side application to pull them out of the database and present in the non-browser UI?

J.D.

vijaykoul
Feb 15th 2005, 11:14 pm
yes J.D, u r right
i am using VB and SQL SERVER to develop an application software.
i want to store images in the database
all the articles I have gone thru have only one answer.
they say, store images at some different place on the hard disk and place a pointer of that location in the database field.
that will slow down the application as the images will be stored somewhere else
I do not want that

I just want images to be stored in the database as any other data is stored
VJK

daboss
Feb 16th 2005, 12:43 am
how will storing the images outside the database slow down the response? i don't think the difference (if any) will be noticeable. in fact, i would have thought that the response would be faster.

the only scenario i would store the images in the database is if i cannot get someone to code a service to retrieve the images to be delivered to the clients.

the use of a middle-tier service will remove the necessity of the clients to have a direct connection with the location where the images are stored - i.e. only one connection (by the service) is required to the location of the images. all the clients requests will be serviced by the service. the service can be coded using any winsock control.

vijaykoul
Feb 16th 2005, 9:54 pm
hi daboss,

dont u think retrieving files again and again from a different location will slow down the process. consider a situation where u have more than 10,000 records and u have to fetch them all. it means control will be passed 10,000 times to the the database and then to the respective file(s) where images are stored. isn't it better to store all the images in the database which will fetch the images at the same time the other fields will be retrieved. moreover, we are not allowing clients to directly have any control over the database. only the administrator is to be given all the rights, and i hope he shud be given access. moreover it is the demand of the situation right now for me as our client wants us to do it this way only.

daboss
Feb 20th 2005, 2:27 am
well, if your client is focing the method on you, that's that isn't it... :)

anyway, i've worked with imaging systems for a while now... and this has been a debate all along. my personal preference is still to have the file system take care of retrieving the image from disk and passing it to the requester.

any way you look at it, you still need to pass the indexes to the database and the images needs to be retrieved from disk (either by the file system or by the database engine). whether it's 10000 images retrieved in a single query or not, the individual records still have to be retrieved one at a time by the database engine.

so it boils down to the question of whether it's more efficient to have the file system or the database engine to maintain and upkeep the images on disk.

frud0
Feb 20th 2005, 6:46 am
If the client is insisting, you gotto do what he/she/it says... blob would be the best option here (depending on size, again)..

Some reading to be done:
http://dev.mysql.com/tech-resources/articles/vb-blob-handling.html

That`ll surely help you out...