Intermittant ADO xBrowse error ( thread with Antonio )

Intermittant ADO xBrowse error ( thread with Antonio )

Postby Rick Lipkin » Tue Jul 21, 2009 11:23 pm

To All

Antonio has been working with me on the above subject .. I contuinue to get intermittant ADO errors in the setado method of code ..

Here is the thread and some of the suggested fixes .. if anyone would like to add their comments .. please feel free .. this problem still persists .. I have put the try, catch, end try in production this evening .. will wait to see if this problem re-appears

Rick Lipkin

>>>> Antonio Linares 07/21/09 4:53 PM >>>
> Rick,
>
> You may use a TRY ... CATCH to avoid that error:
>
> ::bKeyCount := {|| GetKeyCount( ::oRs ) }
>
> static function GetKeyCount( oRs )
>
> local nKeyCount := 0
>
> TRY
> nKeyCount = oRs:RecordCount()
> CATCH
> nKeyCount = 0
> END
>
> return nKeyCount
>
> best regards
>
> Antonio
>
>
> 2009/7/21 Richard M. Lipkin <lipkinrm@dhec.sc.gov>:
>> Antonio
>>
>> I have been monitoring the error.log and it seems that line 3765 is still giving us trouble :
>>
>> Rick Lipkin
>>
>> DEFAULT ::bGoTop := {|| If( ::oRs != nil .and. ::oRs:RecordCount() > 0, ::oRs:MoveFirst(), nil ) },;
>> ::bGoBottom := {|| If( ::oRs != nil .and. ::oRs:RecordCount() > 0, ::oRs:MoveLast(), nil ) },;
>> ::bSkip := {| n | AdoSkip( ::oRs, If( n==nil, 1, n ) ) },;
>> ::bBof := {|| ::oRs:Bof },;
>> ::bEof := {|| ::oRs:Eof },;
>> ::bBookMark := {| n | If( n == nil,;
>> If( ::oRs != nil .and. ::oRs:RecordCount() > 0, ::oRs:BookMark, 0 ), ;
>> If( ::oRs != nil .and. ::oRs:RecordCount() > 0, ( ::oRs:BookMark := n ), 0 ) ) }, ;
>> ::bKeyNo := {| n | If( n == nil, ;
>> If( ::oRs != nil .and. ::oRs:RecordCount() > 0, ::oRs:AbsolutePosition, 0 ), ;
>> If( ::oRs != nil .and. ::oRs:RecordCount() > 0, ( ::oRs:AbsolutePosition := n ), 0 ) ) },;
>> ::bKeyCount := {|| If( ::oRs != nil, ::oRs:RecordCount(), 0 ) } // <--- line 3765 ... errors here
>>
>>
>> Application
>> ===========
>> Path and name: J:\VEHICLE\Veh32.Exe (32 bits)
>> Size: 969,216 bytes
>> Time from start: 0 hours 8 mins 52 secs
>> Error occurred at: 07/21/2009, 10:55:04
>> Error description: Error ADODB.Recordset/6 DISP_E_UNKNOWNNAME: RECORDCOUNT
>> Args:
>>
>> Stack Calls
>> ===========
>> Called from: source\rtl\win32ole.prg => TOLEAUTO:RECORDCOUNT(0)
>> Called from: xbrowse.prg => (b)TXBROWSE:SETADO(3765)
>> Called from: xbrowse.prg => TXBROWSE:PAINT(1254)
>> Called from: xbrowse.prg => TXBROWSE:DISPLAY(957)
>> Called from: .\source\classes\CONTROL.PRG => TXBROWSE:HANDLEEVENT(1423)
>> Called from: .\source\classes\WINDOW.PRG => _FWH(3333)
>> Called from: => DIALOGBOXINDIRECT(0)
>> Called from: .\source\classes\DIALOG.PRG => TDIALOG:ACTIVATE(273)
>> Called from: .\source\function\ERRSYSW.PRG => ERRORDIALOG(343)
>> Called from: .\source\function\ERRSYSW.PRG => (b)ERRORSYS(27)
>> Called from: source\rtl\win32ole.prg => TOLEAUTO:RECORDCOUNT(0)
>> Called from: xbrowse.prg => (b)TXBROWSE:SETADO(3765)
>> Called from: xbrowse.prg => TXBROWSE:PAINT(1254)
>> Called from: xbrowse.prg => TXBROWSE:DISPLAY(957)
>> Called from: .\source\classes\CONTROL.PRG => TXBROWSE:HANDLEEVENT(1423)
>> Called from: .\source\classes\WINDOW.PRG => _FWH(3333)
>> Called from: => WINRUN(0)
>> Called from: .\source\classes\WINDOW.PRG => TMDIFRAME:ACTIVATE(952)
>> Called from: MAIN.PRG => MAIN(381)
>>
>>>>> Antonio Linares 7/20/2009 6:39 PM >>>
>> Rick,
>>
>>>
>> Just curious .. why would this now be showing up and it never showed
>> up before, nor could I reproduce it on my machine .. and the
>> oBrw:End() .. I thought closing the winmdi would also close the
>> listbox ??
>>>
>>
>> Difficult to know it. There must be a reason, surely we will discover it :-)
>>
>> The idea of End()ing the browse was to avoid further paintings. The
>> wmdichild ends it also, but if we end it before then no paint may
>> happen.
>>
>>> Do you think this could have something to do with xHarbor's VM ?? .. especially when several other applications are open ??
>>
>> I don't think so. I think it is related to ADO
>>
>> best regards,
>>
>> Antonio
>>>
>>> Thanks
>>> Rick LIpkin
>>>
>>>>>> Antonio Linares 7/20/2009 5:01 PM >>>
>>> Rick,
>>>
>>> Try this:
>>>
>>> ::bKeyCount := {|| If( ::oRs != nil, ::oRs:RecordCount(), 0 ) }
>>>
>>> best regards
>>>
>>> Antonio
>>>
>>>
>>>
>>> 2009/7/20 Richard M. Lipkin <lipkinrm@dhec.sc.gov>:
>>>> Antonio
>>>>
>>>> Here is the modified code as per your suggestion :
>>>>
>>>> /* origional code
>>>>
>>>>
>>>> DEFAULT ::bGoTop := {|| If( ::oRs:RecordCount() > 0, ::oRs:MoveFirst(), nil ) },;
>>>> ::bGoBottom := {|| If( ::oRs:RecordCount() > 0, ::oRs:MoveLast(), nil ) },;
>>>> ::bSkip := {| n | AdoSkip( ::oRs, If( n==nil, 1, n ) ) },;
>>>> ::bBof := {|| ::oRs:Bof },;
>>>> ::bEof := {|| ::oRs:Eof },;
>>>> ::bBookMark := {| n | If( n == nil,;
>>>> If( ::oRs:RecordCount() > 0, ::oRs:BookMark, 0 ), ;
>>>> If( ::oRs:RecordCount() > 0, ( ::oRs:BookMark := n ), 0 ) ) }, ;
>>>> ::bKeyNo := {| n | If( n == nil, ;
>>>> If( ::oRs:RecordCount() > 0, ::oRs:AbsolutePosition, 0 ), ;
>>>> If( ::oRs:RecordCount() > 0, ( ::oRs:AbsolutePosition := n ), 0 ) ) },;
>>>> ::bKeyCount := {|| ::oRs:RecordCount() }
>>>> */
>>>>
>>>> DEFAULT ::bGoTop := {|| If( ::oRs != nil .and. ::oRs:RecordCount() > 0, ::oRs:MoveFirst(), nil ) },;
>>>> ::bGoBottom := {|| If( ::oRs != nil .and. ::oRs:RecordCount() > 0, ::oRs:MoveLast(), nil ) },;
>>>> ::bSkip := {| n | AdoSkip( ::oRs, If( n==nil, 1, n ) ) },;
>>>> ::bBof := {|| ::oRs:Bof },;
>>>> ::bEof := {|| ::oRs:Eof },;
>>>> ::bBookMark := {| n | If( n == nil,;
>>>> If( ::oRs != nil .and. ::oRs:RecordCount() > 0, ::oRs:BookMark, 0 ), ;
>>>> If( ::oRs != nil .and. ::oRs:RecordCount() > 0, ( ::oRs:BookMark := n ), 0 ) ) }, ;
>>>> ::bKeyNo := {| n | If( n == nil, ;
>>>> If( ::oRs != nil .and. ::oRs:RecordCount() > 0, ::oRs:AbsolutePosition, 0 ), ;
>>>> If( ::oRs != nil .and. ::oRs:RecordCount() > 0, ( ::oRs:AbsolutePosition := n ), 0 ) ) },;
>>>> ::bKeyCount := {|| ::oRs != nil .and. ::oRs:RecordCount() }
>>>>
>>>>
>>>> Notice this last line ::bKeyCount := {|| ::oRs != nil .and. ::oRs:RecordCount() } .. if you add >0 , nil to the if expression .. the listbox errors on line 411 .. however if you leave the parameters out .. all seems to work well.
>>>>
>>>> I will keep my fingers crossed and let you know in the next day or two if this works.
>>>>
>>>> Thanks
>>>> Rick Lipkin
>>>>
>>>> Application
>>>> ===========
>>>> Path and name: C:\FOX\VEHSQL\Veh32.Exe (32 bits)
>>>> Size: 3,496,448 bytes
>>>> Time from start: 0 hours 0 mins 6 secs
>>>> Error occurred at: 07/20/2009, 16:36:21
>>>> Error description: Error BASE/1092 Argument error: MIN
>>>> Args:
>>>> [ 1] = N 10000
>>>> [ 2] = U
>>>>
>>>> Stack Calls
>>>> ===========
>>>> Called from: => MIN(0)
>>>> Called from: xbrowse.prg => (b)TXBROWSE:TXBROWSE(411)
>>>> Called from: => TXBROWSE:VSETRANGE(0)
>>>> Called from: xbrowse.prg => (b)TXBROWSE:TXBROWSE(326)
>>>> Called from: => TXBROWSE:KEYCOUNT(0)
>>>> Called from: xbrowse.prg => TXBROWSE:ADJUST(852)
>>>> Called from: xbrowse.prg => TXBROWSE:INITIATE(758)
>>>> Called from: xbrowse.prg => TXBROWSE:CREATEFROMCODE(654)
>>>> Called from: VEHBROW.PRG => _VBROW(231)
>>>> Called from: VEHBROW.PRG => _VEHBROW(41)
>>>> Called from: MAIN.PRG => (b)BUILDMENU(434)
>>>> Called from: .\source\classes\MENU.PRG => TMENU:COMMAND(437)
>>>> Called from: .\source\classes\WINDOW.PRG => TWINDOW:COMMAND(1003)
>>>> Called from: .\source\classes\MDIFRAME.PRG => TMDIFRAME:COMMAND(241)
>>>> Called from: => TMDIFRAME:HANDLEEVENT(0)
>>>> Called from: .\source\classes\WINDOW.PRG => _FWH(3333)
>>>> Called from: => WINRUN(0)
>>>> Called from: .\source\classes\WINDOW.PRG => TMDIFRAME:ACTIVATE(952)
>>>> Called from: MAIN.PRG => MAIN(381)
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>>>> Antonio Linares 7/20/2009 1:24 PM >>>
>>>> Rick,
>>>>
>>>> I would modify these lines in Class TXBrowse:
>>>>
>>>> DEFAULT ::bGoTop := {|| If( ::oRs:RecordCount() > 0,
>>>> ::oRs:MoveFirst(), nil ) },;
>>>> ::bGoBottom := {|| If( ::oRs:RecordCount() > 0,
>>>> ::oRs:MoveLast(), nil ) },;
>>>> ::bSkip := {| n | AdoSkip( ::oRs, If( n==nil, 1, n ) ) },;
>>>> ::bBof := {|| ::oRs:Bof },;
>>>> ::bEof := {|| ::oRs:Eof },;
>>>> ::bBookMark := {| n | If( n == nil,;
>>>> If( ::oRs:RecordCount() > 0,
>>>> ::oRs:BookMark, 0 ), ;
>>>> If( ::oRs:RecordCount() > 0, (
>>>> ::oRs:BookMark := n ), 0 ) ) }, ;
>>>> ::bKeyNo := {| n | If( n == nil, ;
>>>> If( ::oRs:RecordCount() > 0,
>>>> ::oRs:AbsolutePosition, 0 ), ;
>>>> If( ::oRs:RecordCount() > 0, (
>>>> ::oRs:AbsolutePosition := n ), 0 ) ) },;
>>>> ::bKeyCount := {|| ::oRs:RecordCount() }
>>>>
>>>> with If( ::oRs != nil .and. ::oRs:RecordCount() > 0, ...
>>>>
>>>> and see what happens
>>>>
>>>> best regards
>>>>
>>>> Antonio Linares
>>>> http://www.fivetechsoft.com
>>>>
>>>>
>>>> 2009/7/20 Richard M. Lipkin <lipkinrm@dhec.sc.gov>:
>>>>> Antonio
>>>>>
>>>>> I may have a clue to the ADO error with xbrowse .. it appears that the effected users are using a 'print screen' utility to capture a region of the screen and for some reason .. ( after a certain length of time doing this ) .. when the user closes the browse .. the attached error occurs.
>>>>>
>>>>> Could this be a lostfocus error ??
>>>>>
>>>>> Rick Lipkin
>>>>>

User avatar
Rick Lipkin
 
Posts: 2633
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Intermittant ADO xBrowse error ( thread with Antonio )

Postby nageswaragunupudi » Wed Jul 22, 2009 3:20 am

This kind of problems come when the browse window is refreshed after the recordset is closed. This problem is not confined to ADO. This happens even for RDD, if the DBF is closed by the time the refresh takes place.

Closing recordset or dbf should happen as the Very Last action before closing the window, or if can manage to do it, after closing the window. This is easy in case of dialogs. This is what we need to take care of in our application

I mean to say, the problem is not specific to ADO or XBrowse.

But we expect XBrowse to takeover this responsibility ( which other browses won't anyway ), the xbrowse should check if the recordset still exisits and if so is it still in open state and then execute the action. It is not impossible to code like this, but the overhead will be very high.

For example the bkeyCount codeblock should first verify .. If ( oRs != nil .and. oRs:State > 0, oRs:RecordCount(), ....)
It should do like this for every codeblock and also reposition the record pointer. This will impose heavy overhead for browsing.

I feel that the right place to handle this issue is in our code and should be possible, because it is only momentary for a split second at the time of closing the window
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10295
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Intermittant ADO xBrowse error ( thread with Antonio )

Postby nageswaragunupudi » Wed Jul 22, 2009 4:03 am

If( ::oRs != nil .and. ::oRs:RecordCount() > 0, ...

This check is not enough. oRs may not be nil, but it is closed.
The code should be :
If( ::oRs != nil .and. ::oRs:State > 0 , ...... )
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10295
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Intermittant ADO xBrowse error ( thread with Antonio )

Postby nageswaragunupudi » Wed Jul 22, 2009 4:20 am

Mr Rick

Will you please try this and see if you are still getting errors ?
Code: Select all  Expand view
VALID ( oBrw:lCreated := .f., oRs:Close(), .t. )


If this works we can suggest a neater modification to XBrowse.
Note: If oBrw:lCrated is false, XBrowse does not paint. I have a hunch that this should work.

If you still continue to get errors, I am working on some other modifications, which I shall post here after we know the results.

If this approach works, we can have some method in xbrowse like oBrw:Close(), after which xbrowse does not repaint. Then our code can be something like VALID ( oBrw:Close(), oRs:close(), .t. )
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10295
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Intermittant ADO xBrowse error ( thread with Antonio )

Postby Enrico Maria Giordano » Wed Jul 22, 2009 9:45 am

Rick Lipkin wrote:To All

Antonio has been working with me on the above subject .. I contuinue to get intermittant ADO errors in the setado method of code ..

Here is the thread and some of the suggested fixes .. if anyone would like to add their comments .. please feel free .. this problem still persists .. I have put the try, catch, end try in production this evening .. will wait to see if this problem re-appears


Can you provide a reduced and self-contained sample of the problem, please?

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8356
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Intermittant ADO xBrowse error ( thread with Antonio )

Postby Rick Lipkin » Wed Jul 22, 2009 2:04 pm

Enrico, Rao

The data is on a SQL server and does not translate well to .dbf ( rdd ) nor to Access.mdb .. What sets this code apart from the usual .. since this table contains so many rows .. I use a wrapper to call _OpenUM() and the oRsVeh is actually defined static but not initialized until the program runs thru _OpenUM() then I start the browse.

I have worked with antonio to modify the valid to close the browse object first then close the recordset .. here is the snipid of code for the valid close and the actual close routine :

Code: Select all  Expand view

ACTIVATE WINDOW oWND1 ;
         ON INIT( oBrw:SetFocus(), .F. ) ;
         VALID ( IIF( !lOK, ( oBrw:End(), _VehClose(.T.) ), .F. ))

       *  VALID ( IIF( !lOK, _VehClose(.T.), .F. ))
RETURN( .T. )


//------------------------
static FUNCTION _VehClose( lCLEAN ) //, oRsVEH )

IF lCLEAN = .T.
   lOK := .T.

   VEHNUM := oRsVEH:Fields("LICENSE"):Value
   FERASE( "C:\DBOVL\VEHNUM.MEM" )
   SAVE All like VEHNUM to C:\DBOVL\VEHNUM.MEM

  * oBRW:cALIAS:=NIL

  oRsVEH:CLose()
  oRsVeh := NIL

  _CleanUP()

ENDIF

RETURN(.T.)
 


Here is the entire code for the program .. forgive me that I can not produce a small self contained example .. I want to show this code in its entirety for all :

Code: Select all  Expand view

#INCLUDE "FIVEWIN.CH"
#INCLUDE "XBROWSE.CH"

STATIC oWnd1,oBRw,oRsVEH,lOK, oSay, cSay

//----------------------------
FUNCTION _VehBrow( oWNDMDI )

LOCAL oDlg,lOk1, SAYING, cSQL

cSQL := "SELECT * from VEHICLES where AGENEID = '"+xAGENEID+"' order by VNUMBER,LICENSE"

SysReFresh()

lOK  := .F.
LOK1 := .F.

DEFINE DIALOG oDlg                                               ;
       FROM 5, 8 to 10, 75                                       ;
       TITLE "Please be patient    "+cSQL ;
       COLOR "N/W"                                               ;
       STYLE nOr( WS_POPUP,WS_CAPTION,WS_THICKFRAME )

       cSAY  := "Opening Initial  VEHICLES  Data Recordset"

       @ 1,13 SAY oSay  var cSAY  of oDLG COLOR "N/W"
       oDLG:bStart := { | | lOK1 := _OpenUm(oDlg, cSQL ) }

ACTIVATE DIALOG oDLG CENTERED

IF lOK1 = .F.
   _CLeanUP()
   SysReFresh()
   RETURN(.F.)
ENDIF

SysReFresh()

_VBrow(oWndMdi, cSQL )

SysReFresh()

Return(.T.)

//----------------
Static Func _OpenUm(oDlg, cSQL )

LOCAL oErr, SAYING, cSTRING

IF EMPTY( cSQL )
   cSQL := "SELECT * from VEHICLES where AGENEID = '"+xAGENEID+"' order by VNUMBER,LICENSE"
ENDIF

SysReFresh()

oRsVEH := TOleAuto():New( "ADODB.Recordset" )
oRsVEH:CursorType     := 1        // opendkeyset
oRsVEH:CursorLocation := 3        // local cache
oRsVEH:LockType       := 3        // lockoportunistic

TRY
   oRsVEH:Open( cSQL,'Provider='+xPROVIDER+';Data Source='+xSOURCE+';Initial Catalog='+xCATALOG+';User Id='+xUSERID+';Password='+xPASSWORD )
CATCH oErr
   MsgInfo( "Error in Opening VEHICLES table" )
   oDlg:End()
   RETURN(.F.)
END TRY

IF oRsVEH:EOF
   IF xADMIN = 'Y'.or. xWRITE = 'Y' .or. xSUPER = 'Y'
      SAYING := "Could not find any Vehicle records for "+CHR(10)
      SAYING += +cSQL+CHR(10)
      SAYING := "Would you like to Add a record Now ?"+chr(10)

      IF MsgYesNo( SAYING )
         oDlg:End()
         IF _VehView( "A", oRsVeh  )
         ELSE
            oRsVeh:CLose()
            RETURN(.F.)
         ENDIF
      ENDIF

  ELSE
      SAYING := "Could not find any matching records for "+cSQL
      oRsVeh:Close()
      MsgInfo( SAYING )
      oDlg:End()
      RETURN(.F.)
   ENDIF
ENDIF

oDlg:End()
RETURN(.T.)

//--------------------------
*Static Func _VBrow( oRsVEH, oWndMdi, cSQL )

Static Func _VBrow( oWndMdi, cSQL )

LOCAL oDLG, oICO, cTITLE, oERR, SAYING
LOCAL nWD, nHD

PRIVATE VEHNUM

IF FILE( "C:\DBOVL\VEHNUM.MEM" )
   RESTORE from C:\DBOVL\VEHNUM.MEM addit
ELSE
   VEHNUM := "BOGUS"
ENDIF

IF EMPTY( VEHNUM )
   VEHNUM := "BOGUS"
ENDIF

IF .not. oRsVEH:eof

   TRY
      oRsVEH:Find("LICENSE = '"+VEHNUM+"'" )
   CATCH oErr
      SAYING := "For some odd reason the License Num "+vehnum+" could not be found"+CHR(10)
      SAYING += "This is not a catastrotific failure .. "+chr(10)
      SAYING += "However this could be a network issue .. Aborting"+CHR(10)
      MsgInfo( saying )
      oRsVEH:Close()
      SysReFresh()
      RETURN(.F.)
   END TRY

   IF oRsVEH:eof
      TRY
         oRsVEH:MoveFirst()
      CATCH oERR
         SAYING := "For some odd reason there is no first record in the recordset"+chr(10)
         SAYING += "This is not a catastrotific failure .. "+chr(10)
         SAYING += "However this could be a network issue .. Aborting"+CHR(10)
         MsgInfo( saying )
         oRsVEH:Close()
         SysReFresh()
         RETURN(.F.)
      END TRY
   ENDIF

ELSE
      // must have failed to create recordset

   SAYING := "For some odd reason the Full Recordset could not be acomplished"+CHR(10)
   SAYING += "This is not a catastrotific failure .. "+chr(10)
   SAYING += "However this could be a network issue .. Aborting"+CHR(10)
   MsgInfo( saying )
   oRsVEH:Close()
   SysReFresh()
   RETURN(.F.)

ENDIF

IF oRsVEH:eof
   oRsVEH:MoveFirst()
ENDIF

cTITLE := "SELECT * from VEHICLES where AGENCY = '"+xAGENCY+"'"

nWd := GetSysMetrics(0) * .79
nHt := GetSysMetrics(1) * .8

lOK := .F.
DEFINE ICON oICO RESOURCE "KEY"

DEFINE WINDOW oWnd1                        ;
      FROM 10,10 to nHt, nWd PIXEL         ;
      TITLE cTITLE                         ;
      MENU BuildMenu( oRsVeh )             ;
      ICON oICO                            ;
      NOMINIMIZE                           ;
      NOZOOM                               ;
      MDICHILD

@ 0, 0 xBROWSE oBrw of oWnd1               ;
       RECORDSET oRsVeh                    ;
       COLUMNS 'VNUMBER',                  ;
              'TYPE',                      ;
              'LICENSE',                   ;
              'AGENCY',                    ;
              'MEMO',                      ;
              'MAKE',                      ;
              'TYPE',                      ;
              'YEAR',                      ;
              'PROG',                      ;
              'MOTORPOOL',                 ;
              'REGION',                    ;
              'LASTSERVCE',                ;
              'NEXTSERVCE',                ;
              'NEXTMILAGE',                ;
              'SERIALNUMB',                ;
              'ACTIVE',                    ;
              'READONLY'                   ;
       COLSIZES 48,50,80,50,70,120,120,55,95,95,140,80,80,80,190,80,80  ;
       HEADERS "Vnum",                     ;
               "Type",                     ;
               "License",                  ;
               "Agency",                   ;
               "See Memo",                 ;
               "Make",                     ;
               "Model",                    ;
               "Year",                     ;
               "Program",                  ;
               "Mtrpool",                  ;
               "Location",                 ;
               "LastServ",                 ;
               "NextServ",                 ;
               "NextMilage",               ;
               "Serial#",                  ;
               "Act",                      ;
               "ReadOnly"                  ;
       AUTOSORT AUTOCOLS LINES CELL

       oBrw:bClrStd := {|| {CLR_BLACK, if( oRsVeh:Fields("readonly"):Value = 'Y', RGB(179,203,204), CLR_WHITE ) } }

       oBrw:CreateFromCode()
       oWnd1:oClient := oBrw

       oBrw:aCols[2]:bEditValue := { |x|DispType( oRsVeh) }
       oBrw:aCols[5]:bEditValue := { |y|DispMemo( oRsVeh) }

       oBrw:bLDblClick := { |nRow,nCol | _VehView( "V", oRsVeh ) }
       oBrw:bKeyDown   := { |nKey| _Manual( nKey,oRsVeh ) }

ACTIVATE WINDOW oWND1 ;
         ON INIT( oBrw:SetFocus(), .F. ) ;
         VALID ( IIF( !lOK, ( oBrw:End(), _VehClose(.T.) ), .F. ))

       *  VALID ( IIF( !lOK, _VehClose(.T.), .F. ))

RETURN( .T. )

//-----------------------------------
Static Func _Manual( nKEY, oRsVeh )

DO CASE
CASE nKEY = 45     // insert ADD
     _VehView( "A", oRsVeh )
     oBrw:ReFresh()
     SysReFresh()
CASE nKEY = 46     // delete
     VehDel() // oRsVeh )
     oBrw:ReFresh()
     SysReFresh()
ENDCASE

RETURN(NIL)

//------------------------
static FUNCTION _VehClose( lCLEAN ) //, oRsVEH )

IF lCLEAN = .T.
   lOK := .T.

   VEHNUM := oRsVEH:Fields("LICENSE"):Value
   FERASE( "C:\DBOVL\VEHNUM.MEM" )
   SAVE All like VEHNUM to C:\DBOVL\VEHNUM.MEM

  * oBRW:cALIAS:=NIL

  oRsVEH:CLose()
  oRsVeh := NIL

  _CleanUP()

ENDIF

RETURN(.T.)

//------------------//
//
// _VEHVIEW is located in vehview.prg
//

Static FUNCTION BuildMenu( oRsVEH )

LOCAL oMenu1

MENU oMenu1


     MENUITEM "&Add ..."                             ;
               ACTION ( _vehview( "A", oRsVeh ),     ;
                     oBRW:Refresh(), SysReFresh() )  ;
               MESSAGE "Add a new record"

     MENUITEM "&Edit ..."                           ;
               ACTION ( _vehview( "E", oRsVeh ),    ;
                        oBRW:ReFresh(),             ;
                        oBrw:SetFocus() )           ;
               MESSAGE "Edit this record"

     MENUITEM "&Delete ..."                          ;
               ACTION vehdel()                       ;
               MESSAGE "Delete this record"

     MENUITEM "&View ..."                           ;
               ACTION _vehview( "V", oRsVeh )       ;
               MESSAGE "View this record"

     MENUITEM "&Find ..."                           ;
               ACTION ( _vehfind( oRsVEH ),         ;
                        oBRW:Refresh() )            ;
               MESSAGE "Find a Vehicle"

     MENUITEM "&Trans Hist ..."               ;
              ACTION( _TranHist( oRsVeh, oRsVeh:Fields("veheid"):Value ))

     MENUITEM "&Memo ..."               ;
              ACTION( _ViewMemo( "V", oRsVEH, "VEHICLES" ))

     MENUITEM "&Quit"                                ;
               ACTION oWnd1:END()
   ENDMENU

RETURN( oMenu1 )


//--------------------
static FUNCTION VehDel() // oRsVeh )

LOCAL SAYING, cEID, oRsTrip, oRsWork, oRsGas, oRsTran
LOCAL oCn, oErr, cSQL
LOCAL cTRIP, cWORK, cGAS


IF xSUPER = 'Y' .or. xADMIN = 'Y'
ELSE
   SAYING := "Sorry ... SUPERVISOR or ADMIN Rights only"
   MsgInfo( SAYING )
   RETURN(.F.)
ENDIF

IF oRsVeh:EOF
   SAYING := "Sorry ... Before you can Delete a "
   SAYING += "record, you have to Add one first"
   MsgInfo( SAYING )
   RETURN(.F.)
ENDIF

SAYING := "Are you sure you want to DELETE"+chr(10)
SAYING += " "+CHR(10)
SAYING += "Vehicle Number "+oRsVeh:Fields("Vnumber"):Value+chr(10)
SAYING += "License Number "+oRsVeh:Fields("license"):Value+chr(10)

IF MsgYesNo( SAYING )

   cTRIP   := 'N'
   cWORK   := 'N'
   cGAS    := 'N'

   cEID := oRsVeh:Fields("veheid"):Value

   oRsTrip := TOleAuto():New( "ADODB.Recordset" )
   oRsTrip:CursorType     := 1        // opendkeyset
   oRsTrip:CursorLocation := 3        // local cache
   oRsTrip:LockType       := 3        // lockoportunistic

   cSQL := "SELECT VEHEID from TRIPS where VEHEID = '"+cEID+"'"

   TRY
      oRsTrip:Open( cSQL,'Provider='+xPROVIDER+';Data Source='+xSOURCE+';Initial Catalog='+xCATALOG+';User Id='+xUSERID+';Password='+xPASSWORD )
   CATCH oErr
      MsgInfo( "Error in Opening TRIPS table" )
      RETURN(.F.)
   END TRY

   IF oRsTrip:eof
   ELSE
      cTRIP := 'Y'
   ENDIF

   oRsTrip:Close()

   oRsGas := TOleAuto():New( "ADODB.Recordset" )
   oRsGas:CursorType     := 1        // opendkeyset
   oRsGas:CursorLocation := 3        // local cache
   oRsGas:LockType       := 3        // lockoportunistic

   cSQL := "SELECT VEHEID from GAS where VEHEID = '"+cEID+"'"

   TRY
      oRsGas:Open( cSQL,'Provider='+xPROVIDER+';Data Source='+xSOURCE+';Initial Catalog='+xCATALOG+';User Id='+xUSERID+';Password='+xPASSWORD )
   CATCH oErr
      MsgInfo( "Error in Opening GAS table" )
      RETURN(.F.)
   END TRY

   IF oRsGas:eof
   ELSE
      cGAS := 'Y'
   ENDIF

   oRsGas:Close()

   oRsWork := TOleAuto():New( "ADODB.Recordset" )
   oRsWork:CursorType     := 1        // opendkeyset
   oRsWork:CursorLocation := 3        // local cache
   oRsWork:LockType       := 3        // lockoportunistic

   cSQL := "SELECT VEHEID from WORKORD where VEHEID = '"+cEID+"'"

   TRY
      oRsWork:Open( cSQL,'Provider='+xPROVIDER+';Data Source='+xSOURCE+';Initial Catalog='+xCATALOG+';User Id='+xUSERID+';Password='+xPASSWORD )
   CATCH oErr
      MsgInfo( "Error in Opening WORKORD table" )
      RETURN(.F.)
   END TRY

   IF oRsWork:eof
   ELSE
      cWORK := 'Y'
   ENDIF

   oRsWork:Close()

   IF cTRIP = 'Y' .or. cGAS = 'Y' .or. cWORK = 'Y'

      SAYING := "WARNING .. it appears that there are associated records"+chr(10)
      SAYING += "with this Vehicle :"+chr(10)
      SAYING += " "+CHR(10)
      SAYING += "Trips             "+cTRIP+CHR(10)
      SAYING += "Gas               "+cGAS+CHR(10)
      SAYING += "Work Ord     "+cWORK+CHR(10)
      SAYING += " "+CHR(10)
      SAYING += "If you DELETE this Vehicle you will ORPHAN the above records"+chr(10)
      SAYING += " "+chr(10)
      SAYING += "Are you SURE you want to Proceed and DELETE this Vehicle ?"+chr(10)

      IF MsgNoYes( SAYING )
      ELSE
         MsgInfo( "Deletion Aborted by User" )
         RETURN(.F.)
      ENDIF

   ENDIF

   oCn := CREATEOBJECT( "ADODB.Connection" )
   TRY
           oCn:Open( 'Provider='+xPROVIDER+';Data Source='+xSOURCE+';Initial Catalog='+xCATALOG+';User Id='+xUSERID+';Password='+xPASSWORD )
   CATCH oERR
           SAYING := "Error in Opening connection to Delete relational records"
           MsgInfo( SAYING )
           RETURN(.F.)
   END TRY

   cSQL := "DELETE from FUNDING where VEHEID = '"+cEID+"'"
   oCn:Execute(cSql)

   cSQL := "DELETE from MOTOR where VEHEID = '"+cEID+"'"
   oCn:Execute(cSql)
   oCn:Close()

   oRsVeh:Delete()

   IF .not. oRsVeh:EOF .or. oRsVeh:bof
      TRY
         oRsVeh:MoveNext()
      CATCH
      END TRY
   ENDIF

ENDIF

oBRW:Refresh(.T.)
SysReFresh()

RETURN(NIL)

//----------------------
Static Func DispType( oRsVEH )

Local cTYPE := SPACE(5)

DO CASE
CASE oRsVEH:Fields("V_TYPE"):Value = "V"
     cTYPE := "VEH"
CASE oRsVEH:Fields("V_TYPE"):Value = "E"
     cTYPE := "EQUIP"
CASE oRsVEH:Fields("V_TYPE"):Value = "B"
     cTYPE := "BOAT"
OTHERWISE
     cTYPE := "UNK"
ENDCASE

RETURN( cTYPE )

//----------------------
Static Func DispMemo( oRsVEH )

Local cMEMO, cMESSAGE

cMEMO    := oRsVeh:Fields("memo"):Value
cMESSAGE := "  "

IF empty(alltrim(cMEMO))
ELSE
   cMESSAGE := " see memo "
ENDIF

RETURN( cMESSAGE )

//---------------------
Static Func _CleanUP()

oWnd1      := NIL
oBRw       := NIL

*oRsVEH     := NIL
*lOK
oSay       := NIL
cSay       := NIL

RETURN(.T.)


// end vehbrow.prg

 
User avatar
Rick Lipkin
 
Posts: 2633
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Intermittant ADO xBrowse error ( thread with Antonio )

Postby nageswaragunupudi » Wed Jul 22, 2009 3:39 pm

VALID ( IIF( !lOK, ( oBrw:End(), _VehClose(.T.) ), .F. ))

This solves the entire problem
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10295
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Intermittant ADO xBrowse error ( thread with Antonio )

Postby Rick Lipkin » Wed Jul 22, 2009 6:06 pm

Rao

I have had the valid clause like that already and I continue to get the errors

VALID ( IIF( !lOK, ( oBrw:End(), _VehClose(.T.) ), .F. ))


Antonio made this suggestion so that the listbox does not repaint .. but for some reason the setado method still fires even after the oRs:Close() .. and that is why we tried to work around that in that method to avoid the nil value of oRs .. :cry:

Rick
User avatar
Rick Lipkin
 
Posts: 2633
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Intermittant ADO xBrowse error ( thread with Antonio )

Postby Enrico Maria Giordano » Wed Jul 22, 2009 8:41 pm

Rick Lipkin wrote:Enrico, Rao

The data is on a SQL server and does not translate well to .dbf ( rdd ) nor to Access.mdb


I don't think that the SQL engine used has anything to do with your problem. Unfortunately is almost impossible (at least for me) to help you without a sample.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8356
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Intermittant ADO xBrowse error ( thread with Antonio )

Postby nageswaragunupudi » Wed Jul 22, 2009 11:25 pm

Rick Lipkin wrote:Rao

I have had the valid clause like that already and I continue to get the errors

VALID ( IIF( !lOK, ( oBrw:End(), _VehClose(.T.) ), .F. ))


Antonio made this suggestion so that the listbox does not repaint .. but for some reason the setado method still fires even after the oRs:Close() .. and that is why we tried to work around that in that method to avoid the nil value of oRs .. :cry:

Rick

In that case please try my suggestion earlier.
Code: Select all  Expand view
VALID ( oBrw:lCreated := .f., oRs:Close(), .t. )

TXBrowse does not paint if oBrw:lCreated is false. Let us try this.
I am not able to try here and get back, because I never faced this problem myself.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10295
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Intermittant ADO xBrowse error ( thread with Antonio )

Postby James Bott » Sun Aug 02, 2009 4:19 pm

Rick,

Did you find a solution for this? I find that intermitant errors like this are generally caused by lags in the event que, and are usually solved by a sysrefresh(). I didn't see any mention of sysrefresh() in the thread, did you try that? Also, you could try a timer if that doesn't work.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Intermittant ADO xBrowse error ( thread with Antonio )

Postby Rick Lipkin » Sun Aug 02, 2009 5:14 pm

James

Here is the latest iteration of the setado method and the GetKeycount() trap for the recordset being nil. Upon a valid close .. for some reason the ::oRs becomes nil prematurely or ( perhaps ) the SetAdo method is being called after the recordset has been destroyed .. thus causing the error.

The only common thread has been two of the same users that have lots of programs open in the background .. then attempt to close the browse intermittantly tripping the run-time recordsetkeycount(0) error..

My problem testers have been on vacation the past week and I have not had any feedback on whether the 'trap' has been sprung in the GetKeyCount() function .. I am hoping that oRs will become nil or even perhaps 'destroyed' and the oRs parameter will pop up as empty() ??

This problem has only plagued the same two users and again .. they have lots of programs open and in many cases use a ( screen ) cut and paste tool to extract part of the detail screen in the listbox .. my initial gut reaction led me to think this may be a VM or memory leak due to the ( cut and paste ) print screen utility or maybe in a low memory situation .. a premature release of the oRs value as well.

Just don't have an answer yet.

Rick


Code: Select all  Expand view

// excerpt from setado method

  DEFAULT ::bGoTop    := {|| If( ::oRs != nil .and. ::oRs:RecordCount() > 0, ::oRs:MoveFirst(), nil ) },;
           ::bGoBottom := {|| If( ::oRs != nil .and. ::oRs:RecordCount() > 0, ::oRs:MoveLast(), nil )  },;
           ::bSkip     := {| n | AdoSkip( ::oRs, If( n==nil, 1, n ) ) },;
           ::bBof      := {|| ::oRs:Bof },;
           ::bEof      := {|| ::oRs:Eof },;
           ::bBookMark := {| n | If( n == nil,;
                                 If( ::oRs != nil .and. ::oRs:RecordCount() > 0, ::oRs:BookMark, 0 ), ;
                                 If( ::oRs != nil .and. ::oRs:RecordCount() > 0, ( ::oRs:BookMark := n ), 0 ) ) }, ;
           ::bKeyNo    := {| n | If( n == nil, ;
                                 If( ::oRs != nil .and. ::oRs:RecordCount() > 0, ::oRs:AbsolutePosition, 0 ), ;
                                 If( ::oRs != nil .and. ::oRs:RecordCount() > 0, ( ::oRs:AbsolutePosition := n ), 0 ) ) },;
            ::bKeyCount := {|| GetKeyCount( ::oRs ) }  // static fix

//----------------------------------
// fix for recordcount error

Static function GetKeyCount( oRs )

local nKeyCount := 0

if empty( oRs )
   msginfo( "oRs is nil" )
   RETURN( 0 )
ENDIF


TRY
  nKeyCount := oRs:RecordCount()
CATCH
  nKeyCount := 0
END

return( nKeyCount )
 
User avatar
Rick Lipkin
 
Posts: 2633
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 34 guests