PC SOFT

GRUPOS DE DISCUSSÃO PROFISSIONAL
WINDEVWEBDEV e WINDEV Mobile

Inicio → WINDEV 2024 → Inserting an image into a SQL Server VarBinary(Max) Field using WDBinaryMemo
Inserting an image into a SQL Server VarBinary(Max) Field using WDBinaryMemo
Iniciado por Lee Shroder, mai., 22 2020 6:00 PM - Sem resposta
Publicado em maio, 22 2020 - 6:00 PM
Hello everyone and I hope you are all safe and well in these unprecedented times.

I am hoping someone may be able to shine some light on an issue that so far I have been unable to solve. The task should be a simple one, saving a jpg image into a VarBinary(Max) field in MS SQL Server (SQL Express) utilising SQLConnectWS from an Android solution connecting with the Reserved Server for connecting to external databases.

Here is the code we have been testing with and if we replace the WDBinaryMemo line with a NULL line it works fine.

sSQL is string
nConnect is int
sDate is string
sPhoto is string = "C:\Temp\Happy.jpg"
sDate = DateToString(DateSys(),"MM/DD/YY") + " " + TimeToString(TimeSys(),"HH:MM:SS")

HDeleteAll(Picture)

IF fFileExist(sPhoto) = True THEN

Picture.FileName = sPhoto
Picture.GPSLat = ""
Picture.GPSLong = ""
Picture.KeyID = 1
Picture.Notes = "Test From Emulator"
Picture.PicDateTime = DateSys() + TimeSys
Picture.PictureTypeID = ""
Picture.USERID = 1
HAdd(Picture,hAffectBrowse)

IF InternetConnected() = True THEN

nConnect = SQLConnectWS(gsWSAddress,gsODBC, gsWSUser,gsWSPass, gsWSDataBase,"OLE DB", hODBC)

IF nConnect > 0 THEN

sSQL = "INSERT INTO Picture" + CR
sSQL = sSQL + "(" + CR
sSQL = sSQL + "PictureTypeID," + CR
sSQL = sSQL + "KeyID," + CR
sSQL = sSQL + "Notes," + CR
sSQL = sSQL + "UserID," + CR
sSQL = sSQL + "Photo," + CR
sSQL = sSQL + "Thumbnail," + CR
sSQL = sSQL + "LastLat," + CR
sSQL = sSQL + "PhotoTime," + CR
sSQL = sSQL + "LastLong," + CR
sSQL = sSQL + "PictureFileName," + CR
sSQL = sSQL + "NewPic" + CR
sSQL = sSQL + ")" + CR
sSQL = sSQL + "VALUES" + CR
sSQL = sSQL + "(" + CR
sSQL = sSQL + "1," + CR
sSQL = sSQL + "1," + CR
sSQL = sSQL + "'" + Picture.Notes + "'," + CR
sSQL = sSQL + Picture.USERID + "," + CR
sSQL = sSQL + "NULL," + CR
sSQL = sSQL + "NULL," + CR
sSQL = sSQL + "NULL," + CR
sSQL = sSQL + "'" + sDate + "'," + CR
sSQL = sSQL + "NULL," + CR
sSQL = sSQL + "NULL," + CR
//sSQL = sSQL + "{WDBinaryMemo('" + "C:\Temp\Install.txt" + "','TextFile')}" + CR
sSQL = sSQL + "{WDBinaryMemo('" + Picture.FileName + "'}" + CR
sSQL = sSQL + ")" + CR

IF SQLExec(sSQL,"SendPic") = False THEN

SQLInfo("SendPic")
ToClipboard(SQL.MesError)
Error(SQL.MesError)

END

ELSE

SQLInfo()
Info("SQL error: " + SQL.MesError)

END

END

SQLClose("SendPic")
SQLDisconnect()

ELSE

Error(sPhoto + " not found")

END


The code detailed here has the picture file directly referenced from C:\Temp and we are testing this from the emulator and not on an android device.

On the Reserved Server side we are using ODBC SQL Client 11

Anyone have any ideas as to why this is not working?