FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour ADO Ms Access SLow Close() and Re-Open tables on Win 7
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
ADO Ms Access SLow Close() and Re-Open tables on Win 7
Posted: Wed Jun 03, 2015 09:59 PM
To All

I have a Customer Module that Opens 3 tables from a MS Access database and when I chose a different customer the tables get refreshed by closing them and re-opening them( _custedit() ). The close and re-open process works GREAT on 32 bit Windows XP, but times out on the re-open [Customer Item] table and breaks in the _CustEdit Function.

Here is the code .. all the oRs variables were defined local at the top of the program and passed normally thru the various Functions.

Again, this code works flawlessly on WinXP .. but 'barfs' using Windows 7. I have tried to stay away from using Static oRs variables because this is a MDI application and if the Customer module is opened twice on I have memory 'bleed thru' problems between Customer modules.

Any advice would be welcome ..
Rick Lipkin
Code (fw): Select all Collapse
/Top of Customer module
//------------------------
Func _CustView( cMode,oWndMain )

Local oDlg,lOk1,cSay,oSay,cDefa
Local oRsCust,oRsInvoice,oRsShip,oRsItem

oRsCust     := " "
oRsInvoice  := " "
oRsShip     := " "
oRsItem     := " "


cDEFA := SET(7)

LightGreyGrad()

lOK1   := .F.

DEFINE DIALOG oDlg RESOURCE "FILECHK"       ;
       TITLE "Please be patient"

       cSAY :=  "Opening Tables"
       REDEFINE SAY oSay var cSay ID 120 of oDLG UPDATE

       oDLG:bStart := { || lOK1 := _OpenUm0( oDLG,oSAY,@cSAY,@oRsCust,@oRsInvoice,@oRsShip,@oRsItem ) }

ACTIVATE DIALOG oDLG CENTERED

oSay := NIL
cSay := NIL

IF lOK1 = .F.
   RETURN(NIL)
ENDIF

_CustView1( "A",oWndMain,oRsCust,oRsInvoice,oRsShip,oRsItem)

Return(.t.)

//----------------
Static Func _OpenUm0( oDlg, oSay,cSay, oRsCust,oRsInvoice,oRsShip,oRsItem )

Local cSql,oErr

cSay := "Opening Customer Table"
oSay:ReFresh()
SysReFresh()

// relational key

cSQL := "SELECT * from CUSTOMER order by [Last Name],[First Name]"

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

TRY
   oRsCust:Open( cSQL,xCONNECT )
CATCH oErr
   MsgInfo( "Error in Opening CUSTOMER table" )
   oDlg:End()
   RETURN(.F.)
END TRY

oRsCust:Filter := ""
oRsCust:Filter := "[Last Name] = 'bogus'"

// service address tab
cSay := "Opening Customer ShipTo Table"
oSay:ReFresh()
SysReFresh()

cSQL := "SELECT * from [CUSTOMER SHIPTO] where 1 = 2 order by [Customer Id], [Address1]"

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

TRY
   oRsShip:Open( cSQL,xCONNECT )
CATCH oErr
   oRsCust:Close()
   MsgInfo( "Error in Opening CUSTOMER SHIPTO table" )
   oDlg:End()
   RETURN(.F.)
END TRY

// electronics tab
cSay := "Opening Customer Item Table"
oSay:ReFresh()
SysReFresh()

cSql := "SELECT "
cSql += "[Key],[Customer Id],[Model Number],[Manufacturer Name],[Product Class],[Serial Number] "
cSql += "From [Customer Item] "
cSql += "Where 1 = 2 Order by [Customer Id],[Serial Number]"

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

TRY
   oRsItem:Open( cSQL,xCONNECT )
CATCH oErr
   oRsCust:Close()
   oRsShip:Close()
   MsgInfo( "Error in Opening CUSTOMER ITEM table" )
   oDlg:End()
   RETURN(.F.)
END TRY

// invoice table
cSay := "Opening Invoice Table"
oSay:ReFresh()
SysReFresh()

cSql := "SELECT "
cSql += "[Repair Number], [Transaction Type], [Customer Id],[Invoiced Date], "
cSql += "[Total], [Balance] "
cSql += "From Invoice where 1 = 2 Order by [Invoiced Date] DESC"

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

TRY
   oRsInvoice:Open( cSQL,xCONNECT )
CATCH oErr
   oRsCust:CLose()
   oRsShip:CLose()
   oRsItem:CLose()
   MsgInfo( "Error in Opening INVOICE table" )
   oDlg:End()
   RETURN(.F.)
END TRY

oDlg:End()

Return(.t.)

//-------------------------------
FUNC _Custview1( cMODE,oWnd,oRsCust,oRsInvoice,oRsShip,oRsItem )

...
...
...
// double click on xBrowse new Customer and I close and reopen the tables and here
// is where I have problems

oLbx:bLDblClick := { |nRow,nCol | _CustEdit( oRsCust,oRsShip,oRsItem,oRsInvoice,cCustomerId ..... )

...
...



//---------------------
Static Func _CustEdit( oRsCust,oRsShip,oRsItem,oRsInvoice,cCustomerId... more variables )

...
_OpenUm( oDLG,oSAY,cSAY,oRsItem,oRsInvoice,oRsShip,cCustomerId )
...
...

// sets up the recordset for this customer down stream
//--------------------
Static Func _OpenUm( oDLG,oSAY,cSAY,oRsItem,oRsInvoice,oRsShip,cCustomerId )

...
...

DEFINE DIALOG oDlg RESOURCE "FILECHK"       ;
       TITLE "Please be patient"

       cSAY :=  "Opening Tables"
       REDEFINE SAY oSay var cSay ID 120 of oDLG UPDATE

       oDLG:bStart := { || lOK1 := _OpenUm( oDLG,oSAY,@cSAY,oRsItem,oRsInvoice,oRsShip,cCustomerId ) }

ACTIVATE DIALOG oDLG CENTERED

oSay := NIL
cSay := NIL

IF lOK1 = .F.
    Return(.f.)
ENDIF

   oLbxA:MakeTotals()     // invoices
   oLbxA:ReFresh()
   oLbx2:ReFresh()        // service items
   oLbx3:ReFresh()        // service locations

Endif

Return(.t.)

//--------------------------
Static Func _OpenUm( oDLG,oSAY,cSAY,oRsItem,oRsInvoice,oRsShip,cCustomerId )

Local cSql,oErr

oRsItem:Filter := ""
oRsItem:CLose()

oRsInvoice:Filter := ""
oRsInvoice:Close()
oRsShip:Filter := ""
oRsShip:CLose()


cSay := "Opening Item Customer ShipTo Table"
oSay:ReFresh()
SysReFresh()

cSQL := "SELECT * from [CUSTOMER SHIPTO] where [Customer Id] = '"+alltrim(cCustomerId)+"'"
cSql += " order by [Customer Id], [Address1]"

TRY
   oRsShip:Open( cSQL,xCONNECT )
CATCH oErr
   MsgInfo( "Error in Opening CUSTOMER SHIPTO table" )
   oDlg:ENd()
   RETURN(.F.)
END TRY

cSay := "Opening Invoice Table"
oSay:ReFresh()
SysReFresh()

cSql := "SELECT "
cSql += "[Repair Number], [Transaction Type], [Customer Id],[Invoiced Date], "
cSql += "[Total], [Balance] "
cSql += "From Invoice Where [Customer Id] = '"+alltrim(cCustomerId)+"'"
cSql += " Order by [Invoiced Date] DESC"

TRY
   oRsInvoice:Open( cSQL,xCONNECT )
CATCH oErr
   MsgInfo( "Error in Opening INVOICE table" )
   oDlg:ENd()
   RETURN(.F.)
END TRY

////////////////////
//////////////// locks up here on this table
//////////////// only with Window 7
/////////////////

cSay := "Opening Item Detail Table"
oSay:ReFresh()
SysReFresh()

cSql := "SELECT "
cSql += "[Key],[Customer Id],[Model Number],[Manufacturer Name],[Product Class],[Serial Number] "
cSql += "From [Customer Item] "
cSql += "Where [Customer Id] = '"+alltrim(cCustomerId)+"' Order by [Customer Id],[Serial Number]"

TRY
  oRsItem:Open( cSQL,xCONNECT )
CATCH oErr
  MsgInfo( "Error in Opening CUSTOMER ITEM table" )
  RETURN(.F.)
END TRY

oDlg:End()
Return(.t.)

Posts: 3358
Joined: Fri Oct 07, 2005 08:20 PM
Re: ADO Ms Access SLow Close() and Re-Open tables on Win 7
Posted: Wed Jun 03, 2015 11:23 PM
Rick:

Just an idea, I have not W7, what if you remove the refresh code

Code (fw): Select all Collapse
cSay := "Opening Item Customer ShipTo Table"
oSay:ReFresh()    // This one
SysReFresh()       // And this one too

cSQL := "SELECT * from [CUSTOMER SHIPTO] where [Customer Id] = '"+alltrim(cCustomerId)+"'"
cSql += " order by [Customer Id], [Address1]"

TRY
   oRsShip:Open( cSQL,xCONNECT )
CATCH oErr
   MsgInfo( "Error in Opening CUSTOMER SHIPTO table" )
   oDlg:ENd()
   RETURN(.F.)
END TRY

cSay := "Opening Invoice Table"
oSay:ReFresh()     // This one
SysReFresh()        // And this one too


Regards
SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: ADO Ms Access SLow Close() and Re-Open tables on Win 7
Posted: Thu Jun 04, 2015 12:49 PM

Armando

I think I am going to revise my Customer screen and instead of opening 4 tables, just open the Customer and Invoice and have buttons for the other tables to click and open the other two tables on demand.

I would still like to know why the my current code works GREAT on XP but hangs when closing and re-opening the same table(s) with the same fields with only a parameter change.

Thanks
Rick Lipkin

Continue the discussion