Unable to upload images larger than 131 071 bytes

S

Shawn

Hi. I'm letting the users upload images into a sybase 12.5 database. The
problem is that when ContentLength exceeds 131 071 an exception occur. The
e.Message property is empty so it doesn't tell me much. I know that images
much larger than this exist in the database. Any help is appreciated! Here
is my code:

Dim cn As New Connection
Dim oleDbCommand As OleDbCommand
Dim strSqlImage As String
Dim stream As System.IO.Stream = textBoxImage.PostedFile.InputStream
Dim intFileLength As Integer = textBoxImage.PostedFile.ContentLength
Dim byteArray(intFileLength) As Byte

cn.Open()

stream.Read(byteArray, 0, intFileLength)

strSqlImage = "UPDATE TABLE1 SET image = ? WHERE id = " & intID

oleDbCommand = New OleDbCommand(strSqlImage, cn.oleDbConnection)
oleDbCommand.Parameters.Add(New OleDbParameter("@image",
OleDbType.LongVarBinary)).Value = byteArray

oleDbCommand.ExecuteNonQuery()
 
S

Shawn

The problem isn't uploading bigger files to the server, it's inserting them
into the DB.

Shawn
 
B

bruce barker

haven't used sybase in awhile, but you used to have "set textsize" for arge
text or images, as it defautled to 32k.

-- bruce (sqlwork.com)



| The problem isn't uploading bigger files to the server, it's inserting
them
| into the DB.
|
| Shawn
|
|
| | > Shawn:
| >
| > You'll want to check the value of maxRequestLength in web.config or
| machine.config.
| > It sounds as if the default value has been overridden but perhaps you'll
| > need to bump it up higher.
| >
| > See:
| > PRB: Cannot Upload Large Files When You Use the HtmlInputFile Server
| Control
| > http://support.microsoft.com/default.aspx?scid=kb;en-us;295626
| >
| > --
| > Scott
| > http://www.OdeToCode.com/blogs/scott/
| >
| > > Hi. I'm letting the users upload images into a sybase 12.5 database.
| > > The problem is that when ContentLength exceeds 131 071 an exception
| > > occur. The e.Message property is empty so it doesn't tell me much. I
| > > know that images much larger than this exist in the database. Any help
| > > is appreciated! Here is my code:
| > >
| > > Dim cn As New Connection
| > > Dim oleDbCommand As OleDbCommand
| > > Dim strSqlImage As String
| > > Dim stream As System.IO.Stream = textBoxImage.PostedFile.InputStream
| > > Dim intFileLength As Integer = textBoxImage.PostedFile.ContentLength
| > > Dim byteArray(intFileLength) As Byte
| > > cn.Open()
| > >
| > > stream.Read(byteArray, 0, intFileLength)
| > >
| > > strSqlImage = "UPDATE TABLE1 SET image = ? WHERE id = " & intID
| > >
| > > oleDbCommand = New OleDbCommand(strSqlImage, cn.oleDbConnection)
| > > oleDbCommand.Parameters.Add(New OleDbParameter("@image",
| > > OleDbType.LongVarBinary)).Value = byteArray
| > >
| > > oleDbCommand.ExecuteNonQuery()
| > >
| >
| >
|
|
 
G

Guest

Scott, I stumbled onto this post and think I'm missing something here. I
reviewed the article you list but am expericing an error when I go over
4KB??? I'm saving to SQl Server 2K, field is image. Nothing set in webconfig,
etc.
Any ideas?

Code:
Dim iLength As Integer = CType(inpFileUp.PostedFile.InputStream.Length,
Integer)
If iLength = 0 Then Exit Sub 'not a valid file
Dim sContentType As String = inpFileUp.PostedFile.ContentType
Dim sFileName As String, i As Integer
Dim bytContent As Byte()
ReDim bytContent(iLength) 'byte array, set to file size


'strip the path off the filename
i = InStrRev(inpFileUp.PostedFile.FileName.Trim, "\")
If i = 0 Then
sFileName = inpFileUp.PostedFile.FileName.Trim
Else
sFileName = Right(inpFileUp.PostedFile.FileName.Trim,
Len(inpFileUp.PostedFile.FileName.Trim) - i)
End If

Try
inpFileUp.PostedFile.InputStream.Read(bytContent, 0, iLength)

Response.Write("filesize = " & iLength & "<br>")

'save new image record
Dim cmdInsert As New SqlCommand
Dim insertstring As String
Dim imageid As String

SqlConnect = New SqlConnection(ConnectString)
SqlConnect.Open()

'add company info
insertstring = "INSERT tblImages ( Image_Name, Image_Filename,
Image_Type, Image_FileSize, Image, DateAdded, AddedBy ) VALUES ( @imagename,
@filename, @contenttype, @filesize, @image, @dateadded, @addedby );SELECT
@@Identity" 'using parameters

cmdInsert = New SqlCommand(insertstring, SqlConnect)

With cmdInsert

.Parameters.Add("@imagename", "" & txtimagetitle.Text)
.Parameters.Add("@filename", "" & sFileName)
.Parameters.Add("@contenttype", "" & sContentType)
.Parameters.Add("@filesize", iLength)
.Parameters.Add("@image", bytContent)
.Parameters.Add("@dateadded", Date.Now())
.Parameters.Add("@addedby", Session("contactid"))

End With

imageid = cmdInsert.ExecuteScalar

'close object and connection
SqlConnect.Close()

'add new item to list
ddexistingimages.Items.Add(New ListItem(txtimagetitle.Text,
imageid))

'set label for status
lblstatus.Text = "Image Saved"

Catch ex As Exception
'Handle your database error here

'set label for status
lblstatus.Text = "Error - Please Contact System Administrator."
'close object and connection
SqlConnect.Close()
End Try
 

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

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,744
Latest member
CortneyMcK

Latest Threads

Top