1

I have a column named IMGDATA of type Image in my MyImages in SQL Server server I have a string variable named MyImageStringBase64Encoded that contains a base64 encoded image. I m trying to save this image to the database

Set Command1 = Server.CreateObject ("ADODB.Command")
Command1.ActiveConnection = MyConnection_STRING
Command1.CommandText = "INSERT INTO MyImages (IMGNAME,IMGDATA)  VALUES (?,?)"
Command1.Parameters(0) = "My Image Name"
Command1.Parameters(1) = MyImageStringBase64Encoded
Command1.CommandType = 1
Command1.Execute()

The code above will save corrupted image data in the db. Maybe I have to save bytes?

possibly related but not sure how to apply them

https://stackoverflow.com/a/24925145/934967

MS Access: Sending image as varbinary to stored procedure

I 'm new to vbscript

Nikos Tsagkas
  • 1,287
  • 2
  • 17
  • 31
  • 1
    Does this answer your question? [Converting from base64 string to varbinary(max) in SQL Server](https://stackoverflow.com/questions/25897140/converting-from-base64-string-to-varbinarymax-in-sql-server) – user692942 Sep 11 '20 at 14:58
  • You need to convert the base64 encoded string into it’s binary representation before saving it to SQL Server. – user692942 Sep 11 '20 at 15:00
  • Just noticed you mention [tag:mysql] in the question but the question is tagged [tag:sql-server], which is it? – user692942 Sep 11 '20 at 15:01
  • The `image` data type has been deprecated since SQL Server 2005, you should use the `varbinary(max)` column type instead. You also shouldn't need to base64 encode it, just supply a byte array to the [CreateParameter](https://learn.microsoft.com/en-us/sql/ado/reference/ado-api/createparameter-method-ado) method with the Type set to `adBinary`. – AlwaysLearning Sep 11 '20 at 15:02
  • @AlwaysLearning still depends on if they are using [tag:sql-server] or not but would suggest `adVarBinary` over `adBinary`. – user692942 Sep 11 '20 at 15:29
  • @Lankymart thank you for your comments. Also I edited the typo. It is SQL Server – Nikos Tsagkas Sep 12 '20 at 08:22

0 Answers0