How to detect fail connection to MySql SOLUCIONADO

How to detect fail connection to MySql SOLUCIONADO

Postby D.Fernandez » Sun Jan 17, 2021 6: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.
Last edited by D.Fernandez on Sun Jan 17, 2021 8:45 pm, edited 1 time in total.
Dario Fernandez
FWH 24.09, Harbour, MVS2022 Community, BCC, MySql & MariaDB, Dbf/Cdx VSCode.
Maldonado - Uruguay
D.Fernandez
 
Posts: 463
Joined: Wed Jul 31, 2013 1:14 pm
Location: Maldonado - Uruguay

Re: How to detect fail connection to MySql

Postby nageswaragunupudi » Sun Jan 17, 2021 7:51 pm

As you know, you can also write
Code: Select all  Expand view

FWCONNECT oCn HOST cHost USER cUser PASSWORD cPassword DB cDatbase
 


AS

Code: Select all  Expand view

oCn := maria_Connect( cHost, cDatabase, cUser, cPassword )
 


Now, add logical variable .F. as the last parameter
Code: Select all  Expand view

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: Select all  Expand view

aError := maria_ConnectError() // --> { nError, cErrorDescription }
 

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

Example:
Code: Select all  Expand view

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
User avatar
nageswaragunupudi
 
Posts: 10622
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: How to detect fail connection to MySql

Postby nageswaragunupudi » Sun Jan 17, 2021 7: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
User avatar
nageswaragunupudi
 
Posts: 10622
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: How to detect fail connection to MySql SOLUCIONADO

Postby D.Fernandez » Mon Jan 18, 2021 1:12 am

Thank you very much Mr. Rao.

Regards,

Ruben Dario Fernandez
Dario Fernandez
FWH 24.09, Harbour, MVS2022 Community, BCC, MySql & MariaDB, Dbf/Cdx VSCode.
Maldonado - Uruguay
D.Fernandez
 
Posts: 463
Joined: Wed Jul 31, 2013 1:14 pm
Location: Maldonado - Uruguay

Re: How to detect fail connection to MySql SOLUCIONADO

Postby artu01 » Mon Jan 18, 2021 2: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
artu01
 
Posts: 400
Joined: Fri May 11, 2007 8:20 pm
Location: Lima

Re: How to detect fail connection to MySql

Postby TecniSoftware » 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: Select all  Expand view

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
User avatar
TecniSoftware
 
Posts: 235
Joined: Fri Oct 28, 2005 6:29 pm
Location: Quilmes, Buenos Aires, Argentina

Re: How to detect fail connection to MySql SOLUCIONADO

Postby nageswaragunupudi » Thu Jan 21, 2021 3:12 am

How can I indicate the port number?


Two ways:
1)
Code: Select all  Expand view
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: Select all  Expand view
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
User avatar
nageswaragunupudi
 
Posts: 10622
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: How to detect fail connection to MySql SOLUCIONADO

Postby TecniSoftware » Thu Jan 21, 2021 12:31 pm

nageswaragunupudi wrote:
How can I indicate the port number?


Two ways:
1)
Code: Select all  Expand view
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: Select all  Expand view
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
User avatar
TecniSoftware
 
Posts: 235
Joined: Fri Oct 28, 2005 6:29 pm
Location: Quilmes, Buenos Aires, Argentina


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 64 guests