Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 image problem in sql server & asp.net

Author  Topic 

noanyx
Starting Member

2 Posts

Posted - 2007-09-08 : 04:43:51
Hi friends,
I am using ASP.NET (with C#) and SQL Server 2005 Express Edition.
I have to store images in database.
When I download the image from SQL, it gives exception 'Parameter is not valid.'
I check the size of the byte array and it is really not valid.
I store an image that has a size of 4991 bytes(as a byte array). But when I download it, it has only 13 bytes(byte array again).
This is my upload code :

MemoryStream ms = new MemoryStream();
System.Drawing.Image im = System.Drawing.Image.FromFile(Server.MapPath("Image\\example.gif"));
Byte[] byteArray;
im.Save(ms, ImageFormat.Gif);
byteArray = ms.ToArray();


Here ms.Length is 4983 bytes not 4991! example.gif is 4991 bytes.

My SQL sentence :

"update reklamlar set Resim=" + byteArray + " where ReklamID=1;"

My download code :

byteArray = new byte[reader.GetBytes(4,0,null,0,int.MaxValue)];
mstream.Write(byteArray, 0, byteArray.Length);
System.Drawing.Image im = System.Drawing.Image.FromStream(mstream);


Here byteArray.Lenght is only 13!!!

Please help me what is wrong with this code?
Thanks a lot..

Note : In SQL management studio express, in the image area this text is written : <binary data>
It is 13 characters you see. May be there a relationship???

Kristen
Test

22859 Posts

Posted - 2007-09-08 : 05:02:20
"I have to store images in database"

Can you not store them as files on a fileserver instead, this is generally the preferred method.

Kristen
Go to Top of Page

noanyx
Starting Member

2 Posts

Posted - 2007-09-09 : 07:21:17
Thanks Kristen,
but I have to do it.Database includes all information about members not only the images.Images are logos of the member companies.

Anyone knows what is the problem written in the first message?
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-09-09 : 14:07:17
"Database includes all information about members not only the images."

Indeed, that is common, but so is putting the physical image outside the database.

See: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=55210&SearchTerms=Images,Image

Sorry, but I don't know how to store the answer to your specific question.

Kristen
Go to Top of Page
   

- Advertisement -