Page 1 of 1
How to detect fail connection to MySql SOLUCIONADO
Posted: Sun Jan 17, 2021 6:58 pm
by D.Fernandez
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.
Re: How to detect fail connection to MySql
Posted: Sun Jan 17, 2021 7:51 pm
by nageswaragunupudi
As you know, you can also write
Code: Select all
FWCONNECT oCn HOST cHost USER cUser PASSWORD cPassword DB cDatbase
AS
Code: Select all
oCn := maria_Connect( cHost, cDatabase, cUser, cPassword )
Now, add logical variable .F. as the last parameter
Code: Select all
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
aError := maria_ConnectError() // --> { nError, cErrorDescription }
On that basis you can display the error as you like.
Example:
Code: Select all
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
Re: How to detect fail connection to MySql
Posted: Sun Jan 17, 2021 7:59 pm
by nageswaragunupudi
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.
Re: How to detect fail connection to MySql SOLUCIONADO
Posted: Mon Jan 18, 2021 1:12 am
by D.Fernandez
Thank you very much Mr. Rao.
Regards,
Ruben Dario Fernandez
Re: How to detect fail connection to MySql SOLUCIONADO
Posted: Mon Jan 18, 2021 2:29 am
by artu01
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?
Re: How to detect fail connection to MySql
Posted: Wed Jan 20, 2021 10:02 pm
by TecniSoftware
nageswaragunupudi wrote:As you know, you can also write
Now, add logical variable .F. as the last parameter
Code: Select all
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
Re: How to detect fail connection to MySql SOLUCIONADO
Posted: Thu Jan 21, 2021 3:12 am
by nageswaragunupudi
How can I indicate the port number?
Two ways:
1)
Code: Select all
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
oCn := maria_Connect( "hostaddress:port", cDatabase, cUser, cPassword, .F. )
Note: port can be a part of the address, like "nnn.nnn.nnn:port"
Re: How to detect fail connection to MySql SOLUCIONADO
Posted: Thu Jan 21, 2021 12:31 pm
by TecniSoftware
nageswaragunupudi wrote:How can I indicate the port number?
Two ways:
1)
Code: Select all
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
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!