Transform File data (BUFFER) to BLOB

Hello,

I have stored file data in an MS SQL Server database as a blob. Retrieving this data for operations like attaching it to an email is straightforward by selecting from the table and using the data column as needed.

However, I’m encountering issues when attempting to save file data (Buffer) directly into the database. After attempting this method, the file becomes corrupted.

Could you please provide suggestions or guidance on how to resolve this issue?

I tried:

  • set data = ‘20. Data’ → Implicit conversion from data type varchar to varbinary(max) is not allowed. Use the CONVERT function to run this query.
  • set data = CONVERT(varbinary(max), ‘20. Data’) → works, but file becomes corrupted