VB.NET MySQL blob saving fails for some files -
sometimes saving blob using vb.net mysql db fails. saving pdfs.
when open pdf on computer, works great. save db, , works find. retrieve pdf db again, save file, , can open it.
however acrobat reader not want open newly save pdf, saying file corrupt.
i not sure exactely have flaw in code. nice if help. thank you.
private function pupdateinvoice(byval uguid string, byval upath string) boolean dim rawdata() byte dim fs filestream try fs = new filestream(upath, filemode.open, fileaccess.read) dim ifilesize uint32 ifilesize = fs.length rawdata = new byte(ifilesize) {} fs.read(rawdata, 0, ifilesize) fs.close() if not g_cnwebdb.ping initmysql() end if dim sfilename$ sfilename = cleanfile(upath, false) dim ssql ssql = "update expenses set " & _ "expense_invoicename=@expense_invoicename," & _ "expense_invoicefilesize=@expense_invoicefilesize," & _ "expense_invoiceblob=@expense_invoiceblob," & _ "expense_invoicetype=@expense_invoicetype, " & _ "expense_invoiceexistsinguid=@expense_invoiceexistsinguid " & _ "where " & _ "expense_guid=@expense_guid" dim cmd new mysqlcommand cmd.connection = g_cnwebdb cmd.commandtext = ssql cmd.parameters.addwithvalue("expense_invoicename", sfilename) cmd.parameters.addwithvalue("expense_invoicefilesize", ifilesize) cmd.parameters.addwithvalue("expense_invoiceblob", rawdata) cmd.parameters.addwithvalue("expense_invoicetype", einvoicetype.eit_digital) cmd.parameters.addwithvalue("expense_invoiceexistsinguid", "") cmd.parameters.addwithvalue("expense_guid", uguid) cmd.executenonquery() return true catch ex exception messagebox.show("there error: " & ex.message, "error", _ messageboxbuttons.ok, messageboxicon.error) end try return false end function private sub pshowpdf(byval uguid string) if not g_cnwebdb.ping initmysql() end if dim cmdsel new mysqlcommand("select * expenses expense_guid=" & apo(uguid), g_cnwebdb) dim r mysqldatareader r = cmdsel.executereader if not r.hasrows stop end if r.read() dim filesize uint32 filesize = r.getuint32(r.getordinal("expense_invoicefilesize")) dim rawdata() byte rawdata = new byte(filesize) {} r.getbytes(r.getordinal("expense_invoiceblob"), 0, rawdata, 0, filesize) r.close() dim spath$ spath = "m:\temp.pdf" modio.deletefile(spath) dim fs filestream fs = new filestream(spath, filemode.openorcreate, fileaccess.write) fs.write(rawdata, 0, filesize) fs.close() dim id integer id = system.diagnostics.process.start(spath).id end sub
i chose "blob" column type in db. instead should have chosen "longblob".
Comments
Post a Comment