Page 1 of 1

Check if MYSQL-server is connected

Posted: Mon Dec 20, 2021 1:13 pm
by Marc Vanzegbroeck
Hi,

Is there a fast way to see of the PC is connected to the network with the SQL-server, so he can access the SQL-database.

I have a client with a laptop, and sometimes he's connected to the wrong network, so he can't access the SQL-database.

I Open the the database this way

Code: Select all | Expand

otmp = CREATEOBJECT( "ADODB.Recordset" )
otmp:cursortype :=1
otmp:cursorlocation :=3
otmp:locktype := 3
TRY
     otmp:open(vCommando,ADO_SQL_Connectionstring)
CATCH oErr
     Msgalert( "Fout bij het lezen van de gegevens!")
END TRY
 


It's working fine, but it take 45 seconds before I get the error-message.

Re: Check if MYSQL-server is connected

Posted: Mon Dec 20, 2021 1:32 pm
by Rick Lipkin
Marc

I do something similar and ( yes ) if the connection string is incorrect or the Sql Server is down ... it takes about 20 seconds or so to time out ... '\\

Code: Select all | Expand



xPROVIDER  := "SQLOLEDB"
xSOURCE     := "YourSql Server"
xCatalog      := "YourSqlDatabase"
xUserId        := "Sqluser"
xPASSWORD := "Password"

xSTRING := 'Provider='+xPROVIDER+';Data Source='+xSOURCE+';Initial Catalog='+xCATALOG+';User Id='+xUSERID+';Password='+xPASSWORD

xConnect := CREATEOBJECT( "ADODB.Connection" )

TRY
   xConnect:Open( xString )
CATCH oErr

   // takes about 20-30 seconds to time-out if connection fails

   Saying := "Could not open a Connection to Sql Server   : "+xSource+Chr(10)
   Saying += "Database   : "+xCatalog+chr(10)
   Saying += "  "+chr(10)
   Saying += "Please Contact your System Administrator"+chr(10)
   MsgInfo( Saying )
   RETURN(.F.)
END TRY

 


Rick Lipkin