0

I'm trying to insert an entry into a table that contain a binary image with this query:

INSERT INTO [AlphaDb].[dbo].[ImageThumbnail] (id, imageLinkFunctionId, thumbnail, byDefault)
VALUES ('8da33b6b-ff9e-41be-83d9-ede6edfbb53a', 'a00dbde1-a6be-4f29-b9fc-3d5eb1082c11', 
CONVERT(VARBINARY(MAX), '/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMCAgICAgMCAgIDAwMDBAYEBAQEBAgGBgUGCQgKCgkI
CQkKDA8MCgsOCwkJDRENDg8QEBEQCgwSExIQEw8QEBD/2wBDAQMDAwQDBAgEBAgQCwkLEBAQEBAQ
EBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBD/wgARCAAQABADAREA
AhEBAxEB/8QAFwAAAwEAAAAAAAAAAAAAAAAAAQMEBf/EABcBAAMBAAAAAAAAAAAAAAAAAAABBAP/
2gAMAwEAAhADEAAAAdOemhoGzBf/xAAYEAEAAwEAAAAAAAAAAAAAAAAEAwUGB//aAAgBAQABBQLY
pVe6jCMTVaFCYjdDqUxr6J//xAAbEQABBQEBAAAAAAAAAAAAAAAAAgMEEjEhQv/aAAgBAwEBPwGO
3fR9umEVXKktXk//xAAbEQACAwADAAAAAAAAAAAAAAADEgABAhEhMf/aAAgBAgEBPwExE8gdvXcJ
WWa4Os8tmf/EACYQAAEDAwMCBwAAAAAAAAAAAAECAwQABRESFCEGQSIjMUJhoeH/2gAIAQEABj8C
NiNx2kSJoSBz5rhGrgdzS+njcN5EeQtSCCfA4n1HwcVc4MhzCZCWnkcd9Az9UxHjryiJGdUoY9x/
CK//xAAbEAEAAwEAAwAAAAAAAAAAAAABABEhMVFhof/aAAgBAQABPyEheiMOqOIhuFe4OyjgV1B8
iwxoY4Iw0cmheNPkyC1wogtrrF//2gAMAwEAAgADAAAAEO6v/8QAHhEBAAICAQUAAAAAAAAAAAAA
AQARIVFhQXGhscH/2gAIAQMBAT8QF5VfnghLKzfx5jW3yd4inSe2f//EABwRAAICAgMAAAAAAAAA
AAAAAAABESFBYVHB8P/aAAgBAgEBPxB6UnrbG0IfrWhLh0LNkP/EABkQAQEBAQEBAAAAAAAAAAAA
AAERIQAxcf/aAAgBAQABPxAznzJGKAJ1gpN0qOxxWi7K8oLbx8aSiUpsu5Rn1z51EpIDErvs9vf/
2Q==',2), 'true')

I'm getting this error:

Msg 8114, Level 16, State 5, Line 1
Error converting data type varchar to varbinary.

Where am I wrong?

neptune
  • 1,211
  • 2
  • 19
  • 32
  • Did you read the documentation? What are the possible values for the style parameter? Hint - not 'true'. – SMor Mar 07 '18 at 13:02
  • That's wrong - I see the style now. But the following bit about 'true' has no reason for existence. – SMor Mar 07 '18 at 13:03
  • @SMor I want to insert value for 4 columns. I need 'true' for the byDefault column. – neptune Mar 07 '18 at 13:05
  • Your style indicates the literal is hex - but it is not. There are additional requirements as well (even number of characters) – SMor Mar 07 '18 at 13:08
  • It looks like you're trying to convert Base64-encoded data. [Would you like some help with that?](https://stackoverflow.com/a/32231832/41379160) – Jeroen Mostert Mar 07 '18 at 13:08
  • 1
    @neptune: As Jeroen said you are trying to convert base64 data and you have specified style in `CONVERT(VARBINARY(MAX),.., 2)` <- If you remove this style than your query successfully convert those values onto varbinary. like this - `CONVERT(VARBINARY(MAX), 'your value')`. – Krishnraj Rana Mar 07 '18 at 13:14
  • @KrishnrajRana: that will convert the ASCII representation of the string into a `VARBINARY`, which will certainly allow you to store it, but is not the actual image, and hence almost certainly not what you want (otherwise, you could have just made the column a `VARCHAR(MAX)`). – Jeroen Mostert Mar 07 '18 at 13:33

0 Answers0