Page 1 of 1

FW_OpenAdoConnection reconnect

PostPosted: Wed Dec 13, 2023 10:37 pm
by cdmmaui
Hello Everyone,

Is it possible to determine if FW_OpenAdoConnection is still alive before a FW_OpenRecordSet call and if it is NOT, is there a way to reestablish connection? Here is my sample code establishing connection.

oCn := FW_OpenAdoConnection( "MSSQL,"+xSOURCE+","+xDATABASE2+","+xUSERID+","+XPASSWORD, .T. )
if oCn == nil
? "Failed to connect to Server"
return nil
endif

Thank you!

Re: FW_OpenAdoConnection reconnect

PostPosted: Thu Dec 14, 2023 3:57 am
by nageswaragunupudi
Please check the value of oCn:State.
If the value is 0, the connection is closed. If the value >= 1 the connection is open and the actual value depends on the current activity.

If oCn is closed we can try reconnect by oCn:Open()

This is a sample code to check the connection status and try to reconnect.
Code: Select all  Expand view
function Check( oCn )

   if oCn:State == 0
      TRY
         oCn:Open()
      CATCH
         ? "Can not reconnect"
      END
   endif
   
return ( oCn:State > 0 )


If still the connection can not be re-established, the possible reasons can be loss of internet connection, or physical network issues. This indicates the need for the user to physically remedy the situation and retry the operaration.

Re: FW_OpenAdoConnection reconnect

PostPosted: Thu Dec 14, 2023 4:00 am
by cdmmaui
Thank you Rao

Re: FW_OpenAdoConnection reconnect

PostPosted: Thu Dec 14, 2023 4:24 am
by nageswaragunupudi
Code: Select all  Expand view
oCn := FW_OpenAdoConnection( "MSSQL,"+xSOURCE+","+xDATABASE2+","+xUSERID+","+XPASSWORD, .T. )


We can also write like this:

Code: Select all  Expand view
oCn := FW_OpenAdoConnection( { "MSSQL", xSOURCE, xDATABASE2, xUSERID, XPASSWORD }, .T. )

Re: FW_OpenAdoConnection reconnect

PostPosted: Thu Dec 14, 2023 7:53 am
by Maurizio
Hello Rao
how to specify the port with FW_OpenAdoConnection() ?

Maurizio

Re: FW_OpenAdoConnection reconnect

PostPosted: Thu Dec 14, 2023 10:09 am
by nageswaragunupudi
"ServerAddress:port"

eg:
Code: Select all  Expand view
190.30.20.20:3306

Re: FW_OpenAdoConnection reconnect

PostPosted: Thu Dec 14, 2023 10:59 am
by Maurizio
Thank you Rao