FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How to detect fail connection to MySql SOLUCIONADO
Posts: 555
Joined: Wed Jul 31, 2013 01:14 PM
How to detect fail connection to MySql SOLUCIONADO
Posted: Sun Jan 17, 2021 06:58 PM

Hi friend.
I need help to detect the fail connection to Mysql
If I do...
FWCONNECT oCon HOST chost USER cUser PASSWORD cPassword DB cdatabase
If oCon== nil
MsgInfo("No hay conexxión a la bases de datos","Informe")
Endif

First show an error from mysql-server and later my MsgInfo.
I wish to show my error message only.

Thank you.

Dario Fernandez

FWH 2501, Harbour, MVS2022 Community, MySql & MariaDB, Dbf/Cdx VSCode.

Maldonado - Uruguay
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: How to detect fail connection to MySql
Posted: Sun Jan 17, 2021 07:51 PM
As you know, you can also write
Code (fw): Select all Collapse
FWCONNECT oCn HOST cHost USER cUser PASSWORD cPassword DB cDatbase


AS

Code (fw): Select all Collapse
oCn := maria_Connect( cHost, cDatabase, cUser, cPassword )


Now, add logical variable .F. as the last parameter
Code (fw): Select all Collapse
oCn := maria_Connect( cHost, cDatabase, cUser, cPassword, .F. )

Now, FWH will not display the error and just returns NIL to oCn.

Then, if oCn == nil, you can query the actual error using:
Code (fw): Select all Collapse
aError := maria_ConnectError() // --> { nError, cErrorDescription }

On that basis you can display the error as you like.

Example:
Code (fw): Select all Collapse
oCn := maria_Connect( cHost, cDatabase, cUser, cPassword, .F. )
if oCn == nil
   aError := maria_ConnectError() // --> { nError, cErrorDescription }
   // examine aError
   MsgInfo( <your error description" )
   return nil
endif
Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: How to detect fail connection to MySql
Posted: Sun Jan 17, 2021 07:59 PM

Hope you already know that FWH displays all your error messages in your language.
If you are not clear, please let us know and we will assist you.

Regards



G. N. Rao.

Hyderabad, India
Posts: 555
Joined: Wed Jul 31, 2013 01:14 PM
Re: How to detect fail connection to MySql SOLUCIONADO
Posted: Mon Jan 18, 2021 01:12 AM

Thank you very much Mr. Rao.

Regards,

Ruben Dario Fernandez

Dario Fernandez

FWH 2501, Harbour, MVS2022 Community, MySql & MariaDB, Dbf/Cdx VSCode.

Maldonado - Uruguay
Posts: 400
Joined: Fri May 11, 2007 08:20 PM
Re: How to detect fail connection to MySql SOLUCIONADO
Posted: Mon Jan 18, 2021 02:29 AM
nageswaragunupudi wrote:Hope you already know that FWH displays all your error messages in your language.
If you are not clear, please let us know and we will assist you.

mr. rao can explain the method, please?
fwh 17.12, harbour 3.2.0, pelles C, bcc7, Ms-Sql
Posts: 244
Joined: Fri Oct 28, 2005 06:29 PM
Re: How to detect fail connection to MySql
Posted: Wed Jan 20, 2021 10:02 PM
nageswaragunupudi wrote:As you know, you can also write

Now, add logical variable .F. as the last parameter
Code (fw): Select all Collapse
oCn := maria_Connect( cHost, cDatabase, cUser, cPassword, .F. )




Mr. RAO:

How can I indicate the port number?
Like D.Fernandez I would like to see a personalized message when I cannot connect to the server, in my case I use a specific port but I don't see how to indicate it in your code, normally the fourth parameter is the port number

Regards
Alejandro Cebolido

Buenos Aires, Argentina
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: How to detect fail connection to MySql SOLUCIONADO
Posted: Thu Jan 21, 2021 03:12 AM
How can I indicate the port number?


Two ways:
1)
Code (fw): Select all Collapse
oCn := maria_Connect( cHost, cDatabase, cUser, cPassword, nPort, .F. )

Note: ".F." can be the last parameter after providing all parameters. Position of this parameter is not important

OR

2)
Code (fw): Select all Collapse
oCn := maria_Connect( "hostaddress:port", cDatabase, cUser, cPassword, .F. )

Note: port can be a part of the address, like "nnn.nnn.nnn:port"
Regards



G. N. Rao.

Hyderabad, India
Posts: 244
Joined: Fri Oct 28, 2005 06:29 PM
Re: How to detect fail connection to MySql SOLUCIONADO
Posted: Thu Jan 21, 2021 12:31 PM
nageswaragunupudi wrote:
How can I indicate the port number?


Two ways:
1)
Code (fw): Select all Collapse
oCn := maria_Connect( cHost, cDatabase, cUser, cPassword, nPort, .F. )

Note: ".F." can be the last parameter after providing all parameters. Position of this parameter is not important

OR

2)
Code (fw): Select all Collapse
oCn := maria_Connect( "hostaddress:port", cDatabase, cUser, cPassword, .F. )

Note: port can be a part of the address, like "nnn.nnn.nnn:port"


As always, excellent!

Thank you very much Mr Rao!
Alejandro Cebolido

Buenos Aires, Argentina

Continue the discussion