Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Storing Image to SQL VarBinary Problem
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01242501
Message ID:
01518451
Views:
58
We're using Microsoft SQL Server ODBC Driver Version 06.01.7601

Data Source Name: MyDBName
Data Source Description: Local data
Server: NAOMI-DELL
Database: (Default)
Language: (Default)
Translate Character Data: Yes
Log Long Running Queries: No
Log Driver Statistics: No
Use Regional Settings: No
Prepared Statements Option: Drop temporary procedures on disconnect
Use Failover Server: No
Use ANSI Quoted Identifiers: Yes
Use ANSI Null, Paddings and Warnings: Yes
Data Encryption: No

So I suspect we're out of luck with varbinary(max)

Update. It does seem to work even with ODBC DSN.

>
>
>SQLSETPROP(0,"DispLogin", 2)
>m1 = SQLSTRINGCONNECT("Driver={SQL Server Native Client 10.0};Server=(local)")
>IF m1 < 0
>   AERROR(laError)
>   MessageBox(laError[1,2])
>   RETURN
>ENDIF
>
>TEXT TO lcSQL NOSHOW
>    IF NOT EXISTS(SELECT * FROM sys.databases WHERE Name = 'TestBlob')
>       CREATE DATABASE TestBlob
>ENDTEXT
>IF sqlexec(m1,lcSql) < 0
>   AERROR(laError)
>   MessageBox(laError[1,2])
>   RETURN
>ENDIF
>
>TEXT TO lcSQL NOSHOW
>    IF NOT EXISTS(SELECT * FROM TestBlob.Information_Schema.Tables WHERE Table_Name = 'TestMe ')
>       BEGIN
>          USE TestBlob
>          CREATE TABLE dbo.TestMe  (Mytest varbinary(max))
>      END
>     ELSE
>       TRUNCATE TABLE TestBlob.dbo.TestMe
>ENDTEXT
>IF sqlexec(m1,lcSql) < 0
>   AERROR(laError)
>   MessageBox(laError[1,2])
>   RETURN
>ENDIF
>
>
>cMyImage = GETFILE()
>IF NOT EMPTY(cMyImage)
>   CREATE CURSOR crsTest (Fld1 BLOB)
>   INSERT INTO crsTest VALUES (FILETOSTR(cMyImage))
>   TEXT TO lcSQL NOSHOW PRETEXT 15 TEXTMERGE
>       INSERT INTO TestBlob.dbo.TestMe (Mytest)
>                       VALUES (?crsTest.Fld1)
>   ENDTEXT
>   IF sqlexec(m1,lcSql) < 0
>      AERROR(laError)
>      MessageBox(laError[1,2])
>     RETURN
>   ENDIF
>ENDIF
>
>TRY
>  _screen.RemoveObject("MyImage")
>CATCH
>ENDTRY
>
>
>**** I don't know why it didn't work with Native Cleint 10, but I'm almost sure that it worked with Native Client
>**** I can't test it right know.
>SQLDISCONNECT(0)
>SQLSETPROP(0,"DispLogin", 2)
>m1 = SQLSTRINGCONNECT("Driver={SQL Server};Server=(local)")
>IF m1 < 0
>   AERROR(laError)
>   MessageBox(laError[1,2])
>   RETURN
>ENDIF
>
>
>CLOSE DATABASES ALL
>SET VARCHARMAPPING ON 
>CURSORSETPROP("MapBinary", .t., 0)
>TEXT TO lcSQL NOSHOW PRETEXT 15 TEXTMERGE
>     SELECT * FROM TestBlob.dbo.TestMe
>ENDTEXT
>IF sqlexec(m1,lcSql,[aaa]) < 0
>   AERROR(laError)
>   MessageBox(laError[1,2])
>ENDIF
>CURSORSETPROP("MapBinary", .f., 0)
>_screen.AddObject("MyImage","Image")
>WITH _screen.MyImage AS Image 
>     .Height     = 400
>     .Width      = 400
>     .Top        = 0
>     .Left       = 0
>     .Stretch    = 1 
>     .PictureVal = Mytest
>     .Visible    = .t.
>ENDWITH
>
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform