FW_OpenAdoConnection reconnect

FW_OpenAdoConnection reconnect

Postby cdmmaui » 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
User avatar
cdmmaui
 
Posts: 689
Joined: Fri Oct 28, 2005 9:53 am
Location: Houston ∙ Chicago ∙ Los Angeles ∙ Miami ∙ London ∙ Hong Kong

Re: FW_OpenAdoConnection reconnect

Postby nageswaragunupudi » Thu Dec 14, 2023 3: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: 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.
Regards

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

Re: FW_OpenAdoConnection reconnect

Postby cdmmaui » Thu Dec 14, 2023 4:00 am

Thank you Rao
*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
User avatar
cdmmaui
 
Posts: 689
Joined: Fri Oct 28, 2005 9:53 am
Location: Houston ∙ Chicago ∙ Los Angeles ∙ Miami ∙ London ∙ Hong Kong

Re: FW_OpenAdoConnection reconnect

Postby nageswaragunupudi » Thu Dec 14, 2023 4:24 am

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. )
Regards

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

Re: FW_OpenAdoConnection reconnect

Postby Maurizio » Thu Dec 14, 2023 7:53 am

Hello Rao
how to specify the port with FW_OpenAdoConnection() ?

Maurizio
User avatar
Maurizio
 
Posts: 824
Joined: Mon Oct 10, 2005 1:29 pm

Re: FW_OpenAdoConnection reconnect

Postby nageswaragunupudi » Thu Dec 14, 2023 10:09 am

"ServerAddress:port"

eg:
Code: Select all  Expand view
190.30.20.20:3306
Regards

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

Re: FW_OpenAdoConnection reconnect

Postby Maurizio » Thu Dec 14, 2023 10:59 am

Thank you Rao
User avatar
Maurizio
 
Posts: 824
Joined: Mon Oct 10, 2005 1:29 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 73 guests