SgDotNet
Singapore Professional .NET User Group -For Cool Developers

Any better way to insert image to sql server 2005 using asp.net 2.0?

rated by 0 users
This post has 9 Replies | 1 Follower

Top 10 Contributor
Posts 762
chuawenching Posted: 03-31-2006 7:08 PM

Hi,

  I am curious. Is there any built-in functionality in asp.net 2.0 or vs 2005 to ease this insert image to sql server 2005?

  I had seen some ways through here, and I am looking for the best technique. I prefer to learn to code than using any 3rd party sofware :P

  http://aspalliance.com/articleViewer.aspx?aId=138

  Any help?

Thanks :)

Regards, Chua Wen Ching Believe in yourself, and you will succeed
Top 25 Contributor
Posts 154
i think the sample in the link you gave is good enough, isn't it?
http://feelite.com/blog
Top 25 Contributor
Posts 154
weehyong:


the first guy describe the same thing as the previous link but the second link shows something interesting.
apparently, in sql 2005, the openrowset() function as been enhanced.

but just one question, it seems that the openrowset function cannot insert into columns of image type in the sql table? image columns can take up to 2^31 - 1 bytes while varbinary can take only 8000 bytes, which may not be sufficient for images.
http://feelite.com/blog
Top 10 Contributor
Posts 884

feelite:

but just one question, it seems that the openrowset function cannot insert into columns of image type in the sql table? image columns can take up to 2^31 - 1 bytes while varbinary can take only 8000 bytes, which may not be sufficient for images.

Smile [:)] That's why there is the very usesful MAX keyword..

Check out
  http://sqlservergems.blogspot.com/2006/02/using-max-in-varchar-varbinary-and.html

Top 25 Contributor
Posts 154
ah, another surprise
http://feelite.com/blog
Top 10 Contributor
Posts 1,626

If you are dealing with ASP.NET applications, a convenient way will be to store the images in a folder and then store the link to the image in the database table. That way, you increase the performance of your application (and storage as well).

However, if you need to store images into the database, you will need to convert your image to a byte array before storing it into the table.

I'm curious though. How are you going to retrieve the image and display it back to the web page?

Software development made easy with Paladin RAD Framework. Save some trees, use Stickies.NET
Top 10 Contributor
Posts 884
Firedancer:

If you are dealing with ASP.NET applications, a convenient way will be to store the images in a folder and then store the link to the image in the database table. That way, you increase the performance of your application (and storage as well).

I certainly agree that storing images in a folder, and storing the link to the image in the table is a good idea. In fact, for the past ASP.NET applications that I have developed, this is my default implementation.

In recent years, there has been much thots by different camps on letting the database manage all contents (image, sound, etc), and not just meta-data. (same argument on why WinFS should be like a file-system with a relational feel).

Top 10 Contributor
Posts 762

Ya. Thanks for the reply.

I will look at the links later, coz I am still at home. Plan to go to office later.

Hmm... the reason why I stick to storing image to the database coz of 3 reasons:

a) it is a Proof of Concept demo app. So I don't want to have troubles copying the webserver images later to the deployed machine (just in case, I forgot to copy that folder).

b) Replication issues. As i understand, replication only can copy database not your webserver folders (say images folder).

c) My colleague had developed reporting services that would read images directly from my database. She had yet to find out a way to read from "~/images/" + the filename of the image. So I don't bother to do that :) coz the dateline was near.

Maybe what I did was wrong. Coz I stored the image filename not the whole link.

Thanks anyway.

Regards, Chua Wen Ching Believe in yourself, and you will succeed
Top 10 Contributor
Posts 762

I had posted my findings here

http://community.sgdotnet.org/blogs/chuawenching/archive/2006/04/02/25584.aspx

:)

Regards, Chua Wen Ching Believe in yourself, and you will succeed
Page 1 of 1 (10 items) | RSS
Copyright SgDotNet 2004-2009
Powered by Community Server (Commercial Edition), by Telligent Systems