FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour FW_OpenAdoConnection reconnect
Posts: 708
Joined: Fri Oct 28, 2005 09:53 AM
FW_OpenAdoConnection reconnect
Posted: Wed Dec 13, 2023 10:37 PM

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!

*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: FW_OpenAdoConnection reconnect
Posted: Thu Dec 14, 2023 03:57 AM
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 (fw): Select all Collapse
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.
Regards



G. N. Rao.

Hyderabad, India
Posts: 708
Joined: Fri Oct 28, 2005 09:53 AM
Re: FW_OpenAdoConnection reconnect
Posted: Thu Dec 14, 2023 04:00 AM

Thank you Rao

*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: FW_OpenAdoConnection reconnect
Posted: Thu Dec 14, 2023 04:24 AM
Code (fw): Select all Collapse
oCn := FW_OpenAdoConnection( "MSSQL,"+xSOURCE+","+xDATABASE2+","+xUSERID+","+XPASSWORD, .T. )
We can also write like this:
Code (fw): Select all Collapse
oCn := FW_OpenAdoConnection( { "MSSQL", xSOURCE, xDATABASE2, xUSERID, XPASSWORD }, .T. )
Regards



G. N. Rao.

Hyderabad, India
Posts: 842
Joined: Mon Oct 10, 2005 01:29 PM
Re: FW_OpenAdoConnection reconnect
Posted: Thu Dec 14, 2023 07:53 AM

Hello Rao

how to specify the port with FW_OpenAdoConnection() ?

Maurizio

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: FW_OpenAdoConnection reconnect
Posted: Thu Dec 14, 2023 10:09 AM
"ServerAddress:port"

eg:
Code (fw): Select all Collapse
190.30.20.20:3306
Regards



G. N. Rao.

Hyderabad, India
Posts: 842
Joined: Mon Oct 10, 2005 01:29 PM
Re: FW_OpenAdoConnection reconnect
Posted: Thu Dec 14, 2023 10:59 AM

Thank you Rao

Continue the discussion