Page 1 of 1

Is this Netopen function from 16 bit ok for FWH32 ?

PostPosted: Fri Sep 22, 2017 12:58 pm
by Marc Venken
Hello,

In my project of converting from 16 bit to FWH, i need to change all my Ntx and partial COMIX files to CDX FWH.

I have the folowing code for opening files in FW16 :

Is this code still a good code, (change the COMIX to CDX...) or should I find a better one that uses more of FWH Power.

Maybe someone can share his code to open in network situation ?

At this point, I want to convert strait from 16 to 32. Later I could change to Objects, or other options.

Thanks.


Code: Select all  Expand view
FUNCTION NETOPEN( cFile, lMode, cAlias, nSeconds, lNewArea,cDriver, lReadOnly )
local nWaitTime, lContinue := .t., lSuccess  := .f., TSEL      := 0

DEFAULT lMode     :=  .T.                     // shared mode
DEFAULT nSeconds  :=  3
DEFAULT cAlias    := cFile
DEFAULT lNewArea  :=  .t.
DEFAULT cDriver   := "COMIX"
//DEFAULT cDriver   := "DBFNTX"
DEFAULT lReadOnly :=  .f.
nWaitTime := nSeconds

// bestand het bestand
IF ! FILE( cFile + ".DBF" )
   Exit("Bestand " + CFILE + ".DBF is afwezig")
ENDIF
// verify driver is valid
if ascan( RddList(), cDriver ) == 0
   MSGSTOP("Driver " + Cdriver + "  afwezig")
   Exit()
endif
//
// Indien reeds geopend, alles ok, select waar
//
IF SELECT(cAlias) # 0
   MsgInfo("File was reeds geopend")
   TSEL := SELECT(cAlias)
   SELECT(TSEL)
   lContinue := .t.
   lNewArea  := .f.
ENDIF
// while continuing to attempt open
Do while lContinue // while .not. timed-out
   while nSeconds > 0 .and. lContinue
     //dbUseArea( lNewArea, cDriver, cFile, cAlias, ( .not. lMode ), lReadOnly )
     dbUseArea( lNewArea, cDriver, cFile, cAlias, lMode, lReadOnly )
     // check for success/failure
     IF neterr()
       nSeconds--
       lSuccess  := .F.
      else
       // open successful
       nSeconds  := 0
       lSuccess  := .t.
       lContinue := .f.
     ENDIF
  ENDDO
  IF ! lSuccess
      nSeconds  := nWaitTime
      MSGSTOP("Bestand " + CFILE+" Alias : "+cAlias + " is geopend door een andere gebruiker" + CRLF + CRLF + "Gelieve even te wachten")
      lSuccess   := .F.
      lContinue  := .T.
      lNewArea   := .T.
  ENDIF
ENDDO

return lSuccess
 

Re: Is this Netopen function from 16 bit ok for FWH32 ?

PostPosted: Fri Sep 22, 2017 1:49 pm
by Rick Lipkin
Marc

This User Defined Function has served me well .. the rdd is set for DbfCdx

Rick Lipkin

Code: Select all  Expand view

/* LOGICAL NETUSE( CDATABASE, LOPENMODE, NSECONDS )

  CHARACTER CDATABASE      - NAME OF DATABASE
  LOGICAL LOPENMODE        - OPEN MODE .T. exclusive  .F. shared
  NUMERIC NSECONDS         - NUMBER OF SECONDS TO WAIT  0 forever

  RETURN  .T. if successful,  .F. if not

  SAMPLE CALL  IF NETUSE( "CALLS.DBF", .F., 5 )  // you may need to use the full path and location to open the .dbf
*/

//------------------------------
Func NETUSE( CDATABASE, LOPENMODE, NSECONDS )

LOCAL FOREVER, RESTART, WAIT_TIME, YESNO

RESTART := .T.
FOREVER := ( NSECONDS = 0 )
YESNO   := {"Yes" , "No"}

DO WHILE RESTART

   WAIT_TIME := NSECONDS

   DO WHILE ( FOREVER .OR. WAIT_TIME > 0 )

      IF LOPENMODE
         USE ( CDATABASE ) via "DBFCDX" EXCLUSIVE
      ELSE
         USE ( CDATABASE ) via "DBFCDX" SHARED
      ENDIF

      IF .NOT. NETERR()
         RETURN(.T.)
      ENDIF
      INKEY(1)
      WAIT_TIME--

   ENDDO

   * lock failed, ask to continue

   IF MsgYesNo( "Cannot lock " + CDATABASE + ", retry ?" )
   ELSE
      EXIT
   ENDIF

ENDDO

RETURN(.F.)

 

Re: Is this Netopen function from 16 bit ok for FWH32 ?

PostPosted: Fri Sep 22, 2017 4:29 pm
by TimStone
I use CDX, and tData ( Database objects ). I haven't worried about network locking in YEARS ... it should all be automatic. It's also a lot simpler. ALL of my installs are networked.

Re: Is this Netopen function from 16 bit ok for FWH32 ?

PostPosted: Fri Sep 22, 2017 6:48 pm
by Marc Venken
TimStone wrote:I use CDX, and tData ( Database objects ). I haven't worried about network locking in YEARS ... it should all be automatic. It's also a lot simpler. ALL of my installs are networked.


I totaly agree.. I have more than once talked with James, and got a lot of info, and I'm convinced about Objects. I even use them i smaller apps, but for my bigger program, I first need to get it going in FWH.

Re: Is this Netopen function from 16 bit ok for FWH32 ?

PostPosted: Sun Sep 24, 2017 2:04 pm
by Rick Lipkin
Marc

Along the subject Tim brings up ... you might want to consider moving to the Ado Class and Methods.

https://docs.microsoft.com/en-us/sql/ad ... object-ado

Benefits:

1) Ado oRs code is the same whether you use Ms Sql Server, Ms Access or Oracle .. MySql and MariaDB are similar.
2) Ado leverages Opportunistic Locking where as .DbfCdx has documented Opportunistic Locking performance issues in a Mult-User network environment
3) Ado allows Ms Access and Ms Sql server to share ( virtually ) the same code .. just change the connection string.
4) Modern SQL code is very desirable with many CIO's

It sounds like you are on the verge of a major re-write anyway ... please have a look at the sample AdoRick.Prg .. a good example on how to start using Ado and MS Access .. also on how to implement increment filtering ..

Rick Lipkin

ps .. I thought you were using Ado already in some of your other projects ?