FW_OpenRecordSet and NOWAIT dialog

FW_OpenRecordSet and NOWAIT dialog

Postby damianodec » Tue Oct 26, 2021 8:36 am

Hi,
I have this problem
Code: Select all  Expand view  RUN

...
local oCn := ""
...
oCn := FW_OpenAdoConnection( "connection data...", .t.)

oRs := FW_OpenRecordSet( oCn, "Select...", 1 )

DEFINE DIALOG oDlg RESOURCE "SCHEDA1" OF oWnd FONT oFont TITLE "Scheda"
...

REDEFINE XBROWSE oBrw ;
    RECORDSET oRs;

REDEFINE BTNBMP BtnOk ID 1 OF m_get[32] RESOURCE "ok" 2007        ;
    ACTION (schart01Ok(cGo))

REDEFINE BTNBMP BtnEsc ID 2 OF m_get[32] RESOURCE "chiudi"  2007          ;
    ACTION schart01Esci(@oCn,@oWnd)

ACTIVATE DIALOG m_get[32] CENTERED NOWAIT

*-----------------------------------------------------------------------------------
FUNCTION schart01Esci(m_get, o_get, oCn, oWnd)

m_get[32]:End()

oCn:Close()

Return NIL

 


I call this program from my menu and xBrowse works in DIALOG (FIRST CALL)
then I open again this program BY MENU and xBrowse works too (SECOND CALL)
then I close the first progr (FIRST CALL) by BtnEsc and when I press ok on second program I get:

Stack Calls
===========
Called from: => TOLEAUTO:RECORDCOUNT( 0 )
Called from: .\source\classes\XBROWSE.PRG => ADOSKIP( 10092 )
Called from: .\source\classes\XBROWSE.PRG => (b)TXBROWSE:SETADO( 5590 )

function schart01Esci close oCn that is a local variable inside (FIRST CALL) but it also closes the second connection in (SECOND CALL)

Why?

How can I resolve it ?

Thank you
FiveWin for xHarbour 17.09 - Sep. 2017 - Embarcadero C++ 7.00 for Win32
FWH 64 for Harbour 19.06 (MSVC++) Jun. 2019 - Harbour 3.2.0dev (r1904111533)
Visual Studio 2019 - Pelles C V.8.00.60 (Win64)
User avatar
damianodec
 
Posts: 419
Joined: Wed Jun 06, 2007 2:58 pm
Location: Italia

Re: FW_OpenRecordSet and NOWAIT dialog

Postby Rick Lipkin » Tue Oct 26, 2021 1:47 pm

damianodec

Your Connection string needs to be initialized at the top of your Main program and stay open until you close your program ..

Consider this Mdi Code example"

Code: Select all  Expand view  RUN


Main()

Local cProvider,xSource,xPassword
Public oCN

xPROVIDER := "Microsoft.Jet.OLEDB.4.0"
xSOURCE   := cDEFA+"\Billing.mdb"
xPASSWORD := "password"

xDatabase := "A"  // access  "S" for Sql Server

IF xDATABASE = "A"
   oCN := 'Provider='+xPROVIDER+';Data Source='+xSOURCE+';Jet OLEDB:Database Password='+xPASSWORD
ELSE
   oCn := 'Provider='+xPROVIDER+';Data Source='+xSOURCE+';Initial Catalog='+xCATALOG+';User Id='+xUSERID+';Password='+xPASSWORD
ENDIF

// global connection string
oCn := CREATEOBJECT( "ADODB.Connection" )

TRY
   oCn:Open( xString )
CATCH oErr
   lOk := .f.
END TRY

....
....
...
....
...

// your program menu and code

// end main




#INCLUDE "XBROWSE.CH"

//----------------------------
FUNCTION _ItBrow( oWnd )

LOCAL SAYING,oRsType,oErr,cSQL
LOCAL oICO,oBTN1,oBTN2,oBTN3,oBTN4,oBTN5
LOCAL cTITLE,oLBX,oDLG,oWndChild,cDEFA

Local lOk,oCol

lOK   := .F.
cDEFA := SET(7)


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

cSql := "Select * From [InvoiceType] "
cSql += "Order by [InvoiceType]"

TRY
   oRsType:Open( cSQL,oCn )
CATCH oErr
   MsgInfo( "Error in Opening INVOICETYPE table" )
   RETURN(.F.)
END TRY

cTITLE := "Invoice Type Information"
DEFINE ICON oICO RESOURCE "CROWN"

DEFINE WINDOW oWndChild     ;
       MDICHILD             ;
       FROM 0,1 to 27,47    ;
       NOMINIMIZE           ;
       ICON oICO            ;
       OF oWnd              ;
       TITLE cTitle

DEFINE DIALOG oDlg RESOURCE "ITBROW" of oWndChild

       REDEFINE xBROWSE oLBX             ;
       RECORDSET oRsType                 ;
       COLUMNS "INVOICETYPE"             ;
       COLSIZES 150                      ;
       HEADERS "Invoice Type"            ;
       ID 111 of oDlg                    ;
       AUTOSORT AUTOCOLS LINES CELL

  * oLbx:nMarqueeStyle := MARQSTYLE_HIGHLROW
   oLbx:lRecordSelector := .f.
   oLbx:lHScroll := .f. // turn off horiz scroll bar

   // yesno checkbox
   ADD oCol to oLbx at 2 HEADER 'Letter' size 60     //60
   oLbx:aCols[ 2 ]:addbmpfile( "off" )
   oLbx:aCols[ 2 ]:addbmpfile( "on" )
   oLbx:aCols[ 2 ]:bBmpData := { | lValue |  If(oRsType:eof, ,If( (empty(oRsType:Fields("Letter"):Value) .or.;
                                                      oRsType:Fields("Letter"):Value = "  "), 1, 2 )) }
   oLbx:aCols[ 2 ]:lBtnTransparent := .t.
   oLbx:aCols[ 2 ]:nHeadStrAlign := AL_CENTER

   _BrowColor( oLbx )

 *  oLbx:aCols[4]:nDataStrAlign := AL_RIGHT
 *  oLbx:aCols[4]:nHeadStrAlign := AL_RIGHT

   oLbx:bLDblClick := { |nRow,nCol | _ITView( "V",oRsType,oBtn1,oBtn2,oBtn3,oBtn4,oBtn5 ),oLbx:SetFocus() }


   REDEFINE BTNBMP oBTN1 ID 113           ;
       RESOURCE "ADD16","DADD16","DADD16" ;
       PROMPT "&Add" LEFT 2007;
       ACTION ( _ITView("A",oRsType,oBtn1,oBtn2,oBtn3,oBtn4,oBtn5 ),; // add
                oLBX:ReFresh(),( oLbx:SetFocus(), .F. ) )

   REDEFINE BTNBMP oBTN2 ID 114           ;
   RESOURCE "EDIT16","DEDIT16","DEDIT16"    ;
       PROMPT "&Edit" LEFT 2007;
       ACTION ( _ITView("E",oRsType,oBtn1,oBtn2,oBtn3,oBtn4,oBtn5 ),; // edit
                oLBX:ReFresh(), (oLbx:SetFocus(),.f.) )

   REDEFINE BTNBMP oBTN3 ID 115            ;
       RESOURCE "VIEW16","DVIEW16","DVIEW16" ;
       PROMPT "&View" LEFT 2007;
       ACTION ( _ITView("V",oRsType,oBtn1,oBtn2,oBtn3,oBtn4,oBtn5 ),; // edit
                oLBX:ReFresh(), oLbx:SetFocus() )

   REDEFINE BTNBMP oBTN4 ID 116           ;
       RESOURCE "DELETE16","DDELETE16","DDELETE16" ;
       PROMPT "&Delete" LEFT 2007;
       ACTION ( ITDel( oRsType,oLbx ),  ;
                oLBX:ReFresh(),( oLbx:SetFocus(), .F. ) )

   REDEFINE BTNBMP oBTN5 ID 112           ;
       RESOURCE "CANCEL","DCANCEL","DCANCEL" ;
       PROMPT "&Quit" LEFT 2007;
       ACTION ( lOK1 := .F., oWndChild:END() )

   ACTIVATE DIALOG oDlg NOWAIT ;
        VALID (!GETKEYSTATE( 27 ))  // do not allow esc key here

ACTIVATE WINDOW oWndChild ;
   ON INIT ( oDlg:Move( 0,0, oWndchild:nWidth, oWndchild:nHeight, .T. ),oLbx:SetFocus(), ;
           oWndChild:bResized := {|| _ReSizeUm( oDlg,oWndChild,oLbx) }, ;
           oDlg:refresh(.t.),oLbx:SetFocus());
   VALID ( IIF( !lOK, ExitPgm(.T., oRsType,oWndChild,@lOk ), .F. ))


RETURN( .T. )

//------------------------------
Static Func _ReSizeUm( oDlg,oWndChild,oLbx )

oDlg:SetSize( oWndChild:nWidth, oWndChild:nHeight, .t. ) // frame and dialog link

// dialog controls
oDlg:bResized = { | nSizeType, nWidth, nHeight | ResizeControls( nSizeType, nWidth, nHeight, oDlg )  }

oLbx:SetFocus()

Return(nil)

//-------------------------
Static Func ResizeControls( nSizeType, nWidth, nHeight, oDlg )

*xBrowse(oDlg:aControls)

if nSizeType = 0 //SIZE_MAXIMIZED
                                   // 100              100
   oDlg:aControls[ 1 ]:SetSize( nWidth - 140, nHeight - 68 ) //txbrowse

endif

Return(nil)

//-----------------------
Static FUNCTION ExitPgm( lCLEAN , oRsType, oWndchild,lOk )

LOCAL aDIR, cFILE, cDEFA, lOK1, nNUM

cDEFA := SET(7)
lOK1  := .F.
nNUM  := 0


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

   try
      oRsType:CLose()
   catch
   end try

   oWndChild:End()


ENDIF

RETURN( lOK1 )


 


Note .. The connection String oCn stays open for the entire execution of the program until the program Quits ..

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

Re: FW_OpenRecordSet and NOWAIT dialog

Postby damianodec » Tue Oct 26, 2021 2:54 pm

hi Rick,
thank you.
My program has about 100 menu items and about 50 users are in the lan that use my progr .exe
each item open connection to DB2 and close connection when exit.

Code: Select all  Expand view  RUN

main()
...
MENU oMenu
    MENUITEM o_Menu[01][01] PROMPT "Ufficio Acquisti"
    MENU
        MENUITEM o_Menu[01][02] PROMPT "Esporta catalogo fornitori" ACTION prg1() ;
        MENUITEM o_Menu[01][03] PROMPT "Totale mensile Fornitore e Terzista" ACTION prg2();
        MENUITEM o_Menu[01][04] PROMPT "Zoom mensile Fornitore e Terzista" ACTION prg3() ;
        MENUITEM o_Menu[01][05] PROMPT "Import light" ACTION prg4() ;
        MENUITEM o_Menu[01][05] PROMPT "Import magazzino" ACTION prg5() ;
...

 


each prg (1 2 3 4 5) has:
Code: Select all  Expand view  RUN

oCn := FW_OpenAdoConnection( cStringConn, .t.)
...
oCn:Close()
 


I thought it was better way but you suggest me to open and close it only once into the main ?
FiveWin for xHarbour 17.09 - Sep. 2017 - Embarcadero C++ 7.00 for Win32
FWH 64 for Harbour 19.06 (MSVC++) Jun. 2019 - Harbour 3.2.0dev (r1904111533)
Visual Studio 2019 - Pelles C V.8.00.60 (Win64)
User avatar
damianodec
 
Posts: 419
Joined: Wed Jun 06, 2007 2:58 pm
Location: Italia

Re: FW_OpenRecordSet and NOWAIT dialog

Postby Rick Lipkin » Tue Oct 26, 2021 3:49 pm

Create your Connection once at the top of your program and use that connection to open all your recordsets throughout your application ..


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

Re: FW_OpenRecordSet and NOWAIT dialog

Postby nageswaragunupudi » Wed Oct 27, 2021 9:26 pm

open and close it only once into the main ?

YES
Regards

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

Re: FW_OpenRecordSet and NOWAIT dialog

Postby damianodec » Thu Oct 28, 2021 11:00 am

thank you!
FiveWin for xHarbour 17.09 - Sep. 2017 - Embarcadero C++ 7.00 for Win32
FWH 64 for Harbour 19.06 (MSVC++) Jun. 2019 - Harbour 3.2.0dev (r1904111533)
Visual Studio 2019 - Pelles C V.8.00.60 (Win64)
User avatar
damianodec
 
Posts: 419
Joined: Wed Jun 06, 2007 2:58 pm
Location: Italia

Re: FW_OpenRecordSet and NOWAIT dialog

Postby damianodec » Wed Nov 03, 2021 2:28 pm

hi Mr.Rao
this situation...
Code: Select all  Expand view  RUN

cStringCon = "connection etc etc..."

oCn1 := FW_OpenAdoConnection( cStingConn, .t.)

oCn2 := FW_OpenAdoConnection( cStingConn, .t.)
...

oCn1:Close()
 


close only oCn1 or all connections of cStringCon (oCn1 and oCn2) ?
FiveWin for xHarbour 17.09 - Sep. 2017 - Embarcadero C++ 7.00 for Win32
FWH 64 for Harbour 19.06 (MSVC++) Jun. 2019 - Harbour 3.2.0dev (r1904111533)
Visual Studio 2019 - Pelles C V.8.00.60 (Win64)
User avatar
damianodec
 
Posts: 419
Joined: Wed Jun 06, 2007 2:58 pm
Location: Italia

Re: FW_OpenRecordSet and NOWAIT dialog

Postby nageswaragunupudi » Wed Nov 03, 2021 3:32 pm

damianodec wrote:hi Mr.Rao
this situation...
Code: Select all  Expand view  RUN

cStringCon = "connection etc etc..."

oCn1 := FW_OpenAdoConnection( cStingConn, .t.)

oCn2 := FW_OpenAdoConnection( cStingConn, .t.)
...

oCn1:Close()
 


close only oCn1 or all connections of cStringCon (oCn1 and oCn2) ?


Do not open more connections like oCn1, oCn2, .. etc for the same connection string.
Open only one connection ( oCn ) for one connection string at the beginning and close only when you finally quit the program.

Open all record sets using the same oCn anywhere in your application. Never close the connection in the middle of your program.

Am I clear?
Regards

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

Re: FW_OpenRecordSet and NOWAIT dialog

Postby damianodec » Mon Nov 08, 2021 3:07 pm

ok.

thank you.
FiveWin for xHarbour 17.09 - Sep. 2017 - Embarcadero C++ 7.00 for Win32
FWH 64 for Harbour 19.06 (MSVC++) Jun. 2019 - Harbour 3.2.0dev (r1904111533)
Visual Studio 2019 - Pelles C V.8.00.60 (Win64)
User avatar
damianodec
 
Posts: 419
Joined: Wed Jun 06, 2007 2:58 pm
Location: Italia


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: wilsongamboa and 87 guests