Check if MYSQL-server is connected

Check if MYSQL-server is connected

Postby Marc Vanzegbroeck » Mon Dec 20, 2021 1:13 pm

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 view  RUN
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.
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: Check if MYSQL-server is connected

Postby Rick Lipkin » Mon Dec 20, 2021 1:32 pm

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 view  RUN


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
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 28 guests