-------------------------------------------------
                        VFP 9.0 FIX - SQLSETPROP() FUNCTION
                                 August 2019
                 -------------------------------------------------
                                    CCB



1. BUG:

     In vfp9 (and vfp6, vfp7, vfp8), sometimes the SQLSETPROP(0,"Transactions",1) function occurs an error: Connection 0# is busy (Error 1541).

     The bug only occurs on some Windows versions or some ODBC drivers.


2. CAUSE:

     There are some BUGs in the following code.


3. RESOLUTION:

     We can write some code to fix the BUG.

     Fun882c46 :: ; proc near
             push ebp                                                        ;0x00882c46 :        55
             mov ebp , esp                                                   ;0x00882c47 :        8bec
             sub esp , 0104h                                                 ;0x00882c49 :        81ec04010000
             mov eax ,  dword ptr [ Data937090 ]                             ;0x00882c4f :        a190709300
             push esi                                                        ;0x00882c54 :        56
             mov  esi , dword ptr [ ebp + 8 ]                                ;0x00882c55 :        8b7508
             imul esi , esi , 0158h                                          ;0x00882c58 :        69f658010000
             mov  dword ptr [ ebp - 4 ] , eax                                ;0x00882c5e :        8945fc
             mov eax ,  dword ptr [ Data93b94c ]                             ;0x00882c61 :        a14cb99300
             mov  ecx , dword ptr [eax]                                      ;0x00882c66 :        8b08
             mov  cl , byte ptr [ esi + ecx + 65 ]                           ;0x00882c68 :        8a4c0e41
             test cl , cl                                                    ;0x00882c6c :        84c9
             je Label882cba                                                  ;0x00882c6e :        744a
             movzx ecx , cl                                                  ;0x00882c70 :        660fb6c9
             cmp  cx , word ptr [ ebp + 12 ]                                 ;0x00882c74 :        663b4d0c
             je Label882cba                                                  ;0x00882c78 :        7440
             and  dword ptr [ebx] , 00h                                      ;0x00882c7a :        832300
             mov  eax , dword ptr [eax]                                      ;0x00882c7d :        8b00
             mov  al , byte ptr [ esi + eax + 65 ]                           ;0x00882c7f :        8a440641
             cmp al , 01h                                                    ;0x00882c83 :        3c01
             jne Label882c8e                                                 ;0x00882c85 :        7507
             mov ecx , 01DAh                                                 ;0x00882c87 :        b9da010000
             jmp Label882cb5                                                 ;0x00882c8c :        eb27

     Label882c8e ::
             cmp al , 02h                                                    ;0x00882c8e :        3c02
             jne Label882c99                                                 ;0x00882c90 :        7507
             mov ecx , 01DBh                                                 ;0x00882c92 :        b9db010000
             jmp Label882cb5                                                 ;0x00882c97 :        eb1c

     Label882c99 ::
             cmp al , 03h                                                    ;0x00882c99 :        3c03
             jne Label882ca4                                                 ;0x00882c9b :        7507
             mov ecx , 01DCh                                                 ;0x00882c9d :        b9dc010000
             jmp Label882cb5                                                 ;0x00882ca2 :        eb11

     Label882ca4 ::
             xor ecx , ecx                                                   ;0x00882ca4 :        33c9
             cmp al , 04h                                                    ;0x00882ca6 :        3c04
             setne cl                                                        ;0x00882ca8 :        0f95c1
             dec ecx                                                         ;0x00882cab :        49
             and ecx , 0Ch                                                   ;0x00882cac :        83e10c
             add ecx , 01D1h                                                 ;0x00882caf :        81c1d1010000

     Label882cb5 ::
             call Fun544742                                                  ;0x00882cb5 :        e8881accff

     Label882cba ::
             mov  dword ptr [ebx] , 01h                                      ;0x00882cba :        c70301000000
             cmp  word ptr [ ebp + 12 ] , 02h                                ;0x00882cc0 :        66837d0c02
             je Label882cd8                                                  ;0x00882cc5 :        7411
             mov  ecx , dword ptr [eax]                                      ;0x00882cc7 :        8b08
             lea edx ,  dword ptr [ esi + ecx ]                              ;0x00882cc9 :        8d140e
             cmp  dword ptr [ edx + 48 ] , 00h                               ;0x00882ccc :        837a3000
             je Label882cd8                                                  ;0x00882cd0 :        7406
             test  byte ptr [ edx + 16 ] , 02h                               ;0x00882cd2 :        f6421002
             jne Label882ce3                                                 ;0x00882cd6 :        750b

     Label882cd8 ::
             mov  eax , dword ptr [eax]                                      ;0x00882cd8 :        8b00
             lea edx ,  dword ptr [ esi + eax ]                              ;0x00882cda :        8d1406
             test  byte ptr [ edx + 17 ] , 08h                               ;0x00882cdd :        f6421108
             je Label882d56                                                  ;0x00882ce1 :        7473

     Label882ce3 ::


     ;
     ;                 -------------------------------------------------
     ;                        VFP 9.0 FIX - SQLSETPROP() FUNCTION
     ;                                 August 2019
     ;                 -------------------------------------------------
     ;                                     CCB
     ;
     ; Sometimes the SQLSETPROP(0,"Transactions",1) function occurs an error: Connection 0# is busy (Error 1541).
     ;
     ; 2019/8/30, by ccb
     ;

             cmp  dword ptr [ ebp + 8 ] , 00h
             je Label882d56


             push edi                                                        ;0x00882ce3 :        57
             xor eax , eax                                                   ;0x00882ce4 :        33c0
             pushd 03Fh                                                      ;0x00882ce6 :        6a3f
             mov  byte ptr [ ebp + 0FFFFFEFCh ] , 00h                        ;0x00882ce8 :        c685fcfeffff00
             pop ecx                                                         ;0x00882cef :        59
             lea edi ,  dword ptr [ ebp + 0FFFFFEFDh ]                       ;0x00882cf0 :        8dbdfdfeffff
             rep stosd                                                       ;0x00882cf6 :        f3ab
             mov  ecx , dword ptr [ Data93b948 ]                             ;0x00882cf8 :        8b0d48b99300
             mov  ecx , dword ptr [ecx]                                      ;0x00882cfe :        8b09
             stosw                                                           ;0x00882d00 :        66ab
             mov  edx , dword ptr [edx]                                      ;0x00882d02 :        8b12
             lea eax ,  dword ptr [ edx + 2 * edx ]                          ;0x00882d04 :        8d0452
             shl eax , 05h                                                   ;0x00882d07 :        c1e005
             mov  eax , dword ptr [ eax + ecx + 56 ]                         ;0x00882d0a :        8b440838
             test eax , eax                                                  ;0x00882d0e :        85c0
             pop edi                                                         ;0x00882d10 :        5f
             je Label882d27                                                  ;0x00882d11 :        7414
             mov  ecx , dword ptr [eax]                                      ;0x00882d13 :        8b08
             mov edx , 0FFh                                                  ;0x00882d15 :        baff000000
             lea eax ,  dword ptr [ ebp + 0FFFFFEFCh ]                       ;0x00882d1a :        8d85fcfeffff
             call Fun42c33e                                                  ;0x00882d20 :        e81996baff
             jmp Label882d3e                                                 ;0x00882d25 :        eb17

     Label882d27 ::
             push  dword ptr [ ebp + 8 ]                                     ;0x00882d27 :        ff7508
             lea eax ,  dword ptr [ ebp + 0FFFFFEFCh ]                       ;0x00882d2a :        8d85fcfeffff
             pushd offset Data92ac70                                                  ;0x00882d30 :        6870ac9200
             push eax                                                        ;0x00882d35 :        50
             call Fun43089c                                                  ;0x00882d36 :        e861dbbaff
             add esp , 0Ch                                                   ;0x00882d3b :        83c40c

     Label882d3e ::
             and  dword ptr [ebx] , 00h                                      ;0x00882d3e :        832300
             lea eax ,  dword ptr [ ebp + 0FFFFFEFCh ]                       ;0x00882d41 :        8d85fcfeffff
             call Fun4ba8ba                                                  ;0x00882d47 :        e86e7bc3ff
             mov ecx , 021Dh                                                 ;0x00882d4c :        b91d020000
             call Fun544742                                                  ;0x00882d51 :        e8ec19ccff

     Label882d56 ::
             mov  ecx , dword ptr [ ebp - 4 ]                                ;0x00882d56 :        8b4dfc
             pop esi                                                         ;0x00882d59 :        5e
             call Fun42bf1d                                                  ;0x00882d5a :        e8be91baff
             leave                                                           ;0x00882d5f :        c9
             ret 08h                                                         ;0x00882d60 :        c20800


4. APPLIES TO:

     VFP 6.0.8167.0
     VFP 6.0.8961.0 (SP5)

     VFP 7.0.0.9262
     VFP 7.0.0.9465 (SP1)

     VFP 8.0.0.2521
     VFP 8.0.0.3117 (SP1)

     VFP 9.0.0.2412
     VFP 9.0.0.3504 (SP1)
     VFP 9.0.0.4611 (SP2)
     VFP 9.0.0.5015 (SP2)
     VFP 9.0.0.5411 (SP2)
     VFP 9.0.0.5721 (SP2)
     VFP 9.0.0.5815 (SP2)
     VFP 9.0.0.6303 (SP2)
     VFP 9.0.0.6602 (SP2)
     VFP 9.0.0.7423 (SP2)

     The bug has been fixed in VFP Advanced.


5. REFERENCE WEBSITES:

     1, baiyujia.com:
     http://www.baiyujia.com

     2, microsoft.com:
     https://social.msdn.microsoft.com/forums/en-US/41f0cff8-202b-4fb5-8d84-7295249c9261/connection-0-is-busy

     3, tek-tips.com:
     https://www.tek-tips.com/viewthread.cfm?qid=1746276


6. OTHER:

     For reference only, there is no guarantees.

     Any questions or suggestions, please send me an email at ccb2000@163.com.