Problems with FileStreams and images in jpeg format

S

Suzanne

Hi all,

I'm attempting to save images (that are in jpeg format) to a database
column of type image. I've read over the Microsoft Knowledge Base
articles for this and I can get things working when the image is in a
gif format - but not when the image is in a jpeg format - I get the
error that the file can not be found (& I've checked - the file is
there)!

My code is :
Public Function UpLoadData(ByVal UID As Integer)

Dim dr As SqlDataReader
Dim fs As New FileStream("\\Images\image1.gif", FileMode.Open,
fileAccess.Read)
Dim bytArray(CInt(fs.Length - 1)) As Byte
fs.Read(bytArray, 0, bytArray.Length)
fs.Close()

Dim params() As SqlParameter = {New SqlParameter("@aint_UID",
SqlDbType.Int), _
New SqlParameter("@aimg_Document", SqlDbType.Image,
bytArray.Length)}

params(0).Value = UID
params(1).Value = bytArray

obj_DAL.ExecuteSP("usp_TestImageInsert", params, dr,
DAL.Type.ExecuteNoQuery)
End Function.

Note: obj_DAL is a data access object that opens a sqlconnection and
sets sqlcommand to a stored procedure (this bit works!).

All this code will work as long as the image is in .gif format but not
for .jpeg.

What am I not doing / or doing wrong? When I debug it just gets to
creating the FileStream and then throws the error of the file can not
be found.

Please help!

Thanks
Suzanne
 
M

MSFT

Hi Suzanne,

Are the two files (JIF and JPG) in same folder? Is it possible that you use
a incorrect file name for the JPG file? To make sure this, I suggest you
may check if the file really exists:

for window application:

Msgbox Dir("\\Images\MyJPEG.jpg")

for asp.net application:

Response.wrtie Dir("\\Images\MyJPEG.jpg")

If the file exists, it will display its file name. If not, it will display
a blank string.


Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no

rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top