I have PDF documents stored in my table as binary, the column that stores the bytes for the PDFs is type varbinary(max)
. I want to update
one record with an updated document in SQL Studio, the way I am attempting to accomplish this is like below
UPDATE table
SET file_bytes=CONVERT(varbinary(max),'JVBERi0xLjYNCiW2JqDQo8PC9UeX...0YNCg==') --this is a base64 string
WHERE id='73c75254-ad86-466e-a881-969e2c6e7a04';
The query runs, but when I try to download the document (via the website), it throws an error message that reads PDF header signature not found.
Is this conversion even possible?
Response.ContentType = "application/pdf" Response.AppendHeader("Content-Disposition", "attachment; filename=" & packetName.Replace(".", "_")) Response.BinaryWrite(mergedPdfBytes) Response.End()
'JVBER...'
string, and should it beN'JVBER...'
? Also are you sure you want to store PDF files in a VARBINARY(MAX) column? Most have better luck on the file system or using Filestream or FileTable...cmd.Parameters.Add("@file_bytes", SqlDbType.Binary).Value = fileData.Bytes;
.... this application is already in production, so changing the data type is not an optionN
prefix on the string - I bet it's Unicode (and you lose that when you don't prefix it correctly).