I have a website for a painter where the painter uploads a picture. The picture name is added to a mdb (access) database table, the picture is added to the end of a table called galleries, and the file is uploaded. It is also then resized to a small image.

Sometimes, not always, I get Unrecognized Database Format error after running this. Anyone think of any possible causes and what I can do about them without changing the main structure of the program?

Thanks for your help!

Recommended Answers

All 2 Replies

Is the process you use exactly the same for every image or does it handle different file types in different ways? (jpg, png, bmp, etc.) Hard to really know what's going on without having any code to look at.

I'll post the code. Only jpg imgs are allowed.

 If (FileUpload1.FileName.Substring(FileUpload1.FileName.Length - 4) = ".jpg" And IsNumeric(w.Text) And IsNumeric(h.Text) And IsNothing(title.Text) = False) Then
            conns = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("art.mdb")
            redir = New Recordset
            strSQL = "SELECT COUNT(Title) AS r FROM Paintings WHERE Title='" +title.Text+"'"
            redir.Open(strSQL, conns)
            If Convert.ToInt16(redir.Fields.Item("r").Value) > 0 Then
                Response.Redirect("editgallery.aspx?GID=" + idGallery + "&er=True")
            End If
            FileUpload1.SaveAs(Server.MapPath("~/") & "images\Large\l_" & title.Text.Replace(" ", "").ToLower() & ".jpg")
            FileUpload1.Dispose() //uploaded img
            Dim myCallback As New System.Drawing.Image.GetThumbnailImageAbort(AddressOf ThumbnailCallback)
            Dim myBitmap As System.Drawing.Bitmap
            myBitmap = New System.Drawing.Bitmap(Server.MapPath("images/Large/l_" & title.Text.Replace(" ", "").ToLower() & ".jpg"))
            Dim myThumbnail As Drawing.Image = myBitmap.GetThumbnailImage(165, (165 / myBitmap.Width) * myBitmap.Height, myCallback, IntPtr.Zero) //create a thumbnail
            myThumbnail.Save(Server.MapPath("images\Small\s_" & title.Text.Replace(" ", "").ToLower() & ".jpg"), System.Drawing.Imaging.ImageFormat.Jpeg)
            strSQL = "INSERT INTO Paintings (Title, HeightInches, WidthInches, ImageBaseName) VALUES (""" & title.Text & """, " & h.Text & ", " & w.Text & ", """ & title.Text.Replace(" ", "").ToLower() & """)"
            Dim conn As OleDbConnection = Nothing
            conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("art.mdb"))
            Dim cmd As New OleDbCommand(strSQL, conn)
            conn.Close() //added to paintings table
            conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("art.mdb"))
            maxas = New Recordset
            strSQL = "SELECT MAX(PaintingID) AS maxot FROM Paintings" //new painting is the last one
            maxas.Open(strSQL, conns)
            maxs = New Recordset
            strSQL = "SELECT MAX(Ordering) AS maxot FROM GalleryEntries WHERE GalleryID=" & idGallery
            maxs.Open(strSQL, conns)
            strSQL = "INSERT INTO GalleryEntries VALUES (" & idGallery & ", " & maxas.Fields.Item("maxot").Value & ", " & maxs.Fields.Item("maxot").Value & "+1)" //add to galleryentries table
            cmd = New OleDbCommand(strSQL, conn)
            Response.Redirect("editgallery.aspx?GID=" + idGallery)
        End If

Sorry - it's messy. But exaclty as described.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.