How to detect fail connection to MySql SOLUCIONADO

Post Reply
D.Fernandez
Posts: 392
Joined: Wed Jul 31, 2013 1:14 pm
Location: Maldonado - Uruguay
Contact:

How to detect fail connection to MySql SOLUCIONADO

Post 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.
Last edited by D.Fernandez on Sun Jan 17, 2021 8:45 pm, edited 1 time in total.
Dario Fernandez
FWH, Harbour, BCC, MySql & MariaDB, tData, Dbf/Cdx
VSCode.
Maldonado - Uruguay
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: How to detect fail connection to MySql

Post 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
Regards

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

Re: How to detect fail connection to MySql

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

G. N. Rao.
Hyderabad, India
D.Fernandez
Posts: 392
Joined: Wed Jul 31, 2013 1:14 pm
Location: Maldonado - Uruguay
Contact:

Re: How to detect fail connection to MySql SOLUCIONADO

Post by D.Fernandez »

Thank you very much Mr. Rao.

Regards,

Ruben Dario Fernandez
Dario Fernandez
FWH, Harbour, BCC, MySql & MariaDB, tData, Dbf/Cdx
VSCode.
Maldonado - Uruguay
artu01
Posts: 306
Joined: Fri May 11, 2007 8:20 pm
Location: Lima

Re: How to detect fail connection to MySql SOLUCIONADO

Post 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?
fwh 17.12, harbour 3.2.0, pelles C, bcc7, Ms-Sql
User avatar
TecniSoftware
Posts: 213
Joined: Fri Oct 28, 2005 6:29 pm
Location: Quilmes, Buenos Aires, Argentina

Re: How to detect fail connection to MySql

Post 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
Alejandro Cebolido
Buenos Aires, Argentina
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: How to detect fail connection to MySql SOLUCIONADO

Post 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"
Regards

G. N. Rao.
Hyderabad, India
User avatar
TecniSoftware
Posts: 213
Joined: Fri Oct 28, 2005 6:29 pm
Location: Quilmes, Buenos Aires, Argentina

Re: How to detect fail connection to MySql SOLUCIONADO

Post 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!
Alejandro Cebolido
Buenos Aires, Argentina
Post Reply