Página 1 de 1

Monitorar conexão com o Banco de dados MySQL

Publicado: Jue May 09, 2013 9:15 pm
por Sommus
Prezados desenvolvedores de xailer,
Há alguma maneira de MONITORAR uma conexão com o banco MySQL?
Preciso verificar, num intervalo de tempo (TTimer), ex: a cada 5 segundos,
se o banco está conectado, e atualizar essa informação na tela do sistema.
Tentei isso:
oMySQL:lConnected:=.F.
oMySQL:lConnected:=.T.
Funciona, porém é muito lento, caso não consiga conectar...
Alguma sugestão de como fazer isso?
Obrigado pela atenção,
Reginaldo

Monitorar conexão com o Banco de dados MySQL

Publicado: Jue May 09, 2013 10:54 pm
por emeasoft
Reginaldo,
Também tenho esta rotina e quando !lConnected fica
um pouco lento.
No TMySqlDatasource tem a propriedade nTimeOut, mas testei isto e não faz diferença.

Timeout in miliseconds for server connection and any othe query to it.
Scope
Assignable before the connection to the server
Type
Numeric
Initial value
1000

Mário

Monitorar conexão com o Banco de dados MySQL

Publicado: Mar May 14, 2013 2:18 am
por Sommus
Desenvolvedores de xailer,
Alguma sugestão?
Obrigado!

Monitorar conexão com o Banco de dados MySQL

Publicado: Mar May 14, 2013 11:33 am
por ignacio
Buenos dí­as,
Debe de utilizar nTimeOut para controlar las posibles desconexiones.
Xailer utiliza su propio mecanismo para que las conexiones no se pierdan usando el valor nTimeOut como base de cálculo. Reduzca su valor para forzar que los 'pings' a la BD se hagan con más frecuencia.
Un saludo

Monitorar conexão com o Banco de dados MySQL

Publicado: Mar May 14, 2013 1:09 pm
por emeasoft
Ignacio:
O problema é que se nTimeOut=1000 e .not. lConnected, demora quase
10 segundos para responder.
í‰ assim mesmo?
Mário Angelini

Monitorar conexão com o Banco de dados MySQL

Publicado: Mar May 14, 2013 4:46 pm
por ignacio
Mario,
Intente añadir esta función en cualquiera de sus PRG:
#pragma BEGINDUMP
#include "Windows.h"
#include "Xailer.h"
#include "mysql.h"
HB_FUNC( MYSQL_PING ) // (Handle) --> nResult
{
MYSQL *mysql = (LPVOID) hb_parnl( 1 );
hb_retnl( mysql_ping( mysql ) );
}
#pragma ENDDUMP
Deberá llamarla de la siguiente forrma:
mysql_ping( ::oDataSource:Handle )
Consulte este enlace para más información sobre esa función:
http://dev.mysql.com/doc/refman/5.0/es/mysql-ping.html
Saludos

Monitorar conexão com o Banco de dados MySQL

Publicado: Mar May 14, 2013 5:53 pm
por emeasoft
Hello Ignacio,
Your code is giving this error:
fatal error: mysql.h: No such file or directory
I dont know if something changes, but we are using MariaDB here.
TIA,
Juliano

Monitorar conexão com o Banco de dados MySQL

Publicado: Mar May 14, 2013 6:07 pm
por jfgimenez
Juliano,
> Your code is giving this error:
>
> fatal error: mysql.h: No such file or directory
To avoid using mysql.h, just try this:
//---------------------------------------------------------- --------------------
#pragma BEGINDUMP
#include "Windows.h"
#include "Xailer.h"
int STDCALL mysql_ping(LPVOID mysql);
HB_FUNC( MYSQL_PING )
{
LPVOID mysql = (LPVOID) hb_parnl( 1 );
hb_retnl( mysql_ping( mysql ) );
}
#pragma ENDDUMP
//---------------------------------------------------------- --------------------
> I dont know if something changes, but we are using MariaDB
> here.
Never mind. MariaDB is fully compatible to MySQL ;-)
Regards,
Jose F. Gimenez
http://www.xailer.com
http://www.xailer.info

Monitorar conexão com o Banco de dados MySQL

Publicado: Mar May 14, 2013 7:15 pm
por emeasoft
It worked, thanks for the help José!!
But it unfortunatly does not solve the other problem...
The problem is that when It fails to connect to the server, it takes about 30 seconds to return something... And ignores the ntimeout property.
And the mysql_ping() only works after lConnect is true.
I am sending an example of what is happening.
TIA,
Juliano

Attached files MariaDB TimeOut.zip (3.2 KB)Â

Monitorar conexão com o Banco de dados MySQL

Publicado: Mié May 15, 2013 9:52 am
por jfgimenez
Juliano,
> It worked, thanks for the help José!!
> But it unfortunatly does not solve the other problem...
> The problem is that when It fails to connect to the server,
> it takes about 30 seconds to return something... And ignores
> the ntimeout property.
Well, if server has been disconnected, then it needs some time to
reconnect, it's normal
> And the mysql_ping() only works after lConnect is true.
Yes, of course.
AFAIU, if the server cannot be reached, there are two possible reasons:
1) the network connection has been shutdown. In that case, the only way
to avoid it is to 'ping' to the server regulary (f.e. every 30 seconds
or so). If that doesn't solve the problem, then the problem is not a
timeout issue, but a hardware disconnection.
2) MySQL (or MariaDB) closes the connection. Like the previous case, it
could be avoided by 'pinging' to the server regulary. You may create a
timer to achieve that task, but you have to be care about errors caused
by launch a query while another query is in the way. F.e., the timer
code could be something like:
TRY
::oMySQLDatasource:GetTables()
CATCH
END
Regards,
Jose F. Gimenez
http://www.xailer.com
http://www.xailer.info

Monitorar conexão com o Banco de dados MySQL

Publicado: Mié May 15, 2013 1:12 pm
por emeasoft
Hello José and many thanks for your help and pacience!
But I am not being able to explain very well the issue...
What we want to know is that if is there any way to control
the time that the application is in lBusy state when trying
to reconnect with the server.
TIA,
Juliano

Monitorar conexão com o Banco de dados MySQL

Publicado: Mié May 15, 2013 1:28 pm
por jfgimenez
Juliano,
> Hello José and many thanks for your help and pacience!
>
> But I am not being able to explain very well the issue... What we want
> to know is that if is there any way to control
>
> the time that the application is in lBusy state when trying
>
> to reconnect with the server.
No, AFAIK. When you try to connect to the server, Xailer just call a
function from libmysql.dll, and that function doesn't return until the
task is completed. So, the program keeps "freezed" until libmysql.dll
returns, and there is nothing we can do.
If the reconnection process is done by calling mysql_ping(), the
scenario is exactly the same, since mysql_ping() is just another
function of libmysql.dll.
Regards,
Jose F. Gimenez
http://www.xailer.com
http://www.xailer.info

Monitorar conexão com o Banco de dados MySQL

Publicado: Mié May 15, 2013 1:53 pm
por emeasoft
Oh, I understand Jose, it is something internal in mysql.
Many thanks for your help.
Regards,
Juliano

Monitorar conexão com o Banco de dados MySQL

Publicado: Jue Oct 10, 2013 4:49 pm
por Sommus
Caros Ignacio e Jose Gimenez,
Para monitorar minha conexão estou enviando o seguinte comando a cada 1 segundo:
Application:oMainForm:oMySQL:lConnected:=.T.
A propriedade "nTimeOut" do componente "oMySQL" está 1000
Há algum problema em fazer isso?
Há uma forma melhor de fazer?
Obrigado!
Reginaldo

Monitorar conexão com o Banco de dados MySQL

Publicado: Vie Oct 11, 2013 4:58 am
por martindelangel
Mario Creo entender lo que quieres.
Primero:
Crea un Timer en el formulario principal
en la propiedad nInterval= 60000
Habilitalo lEnabled a .T.
En el Metodo del Timer pon esto:
METHOD TimerMySqlTimer( oSender ) CLASS TMenuPrincipal
::oDBMaria:Ping()
RETURN Nil

oDBMaria es objeto de la conexion a la base de datos , remplazala por nombre que tu usas
Segundo:
Incluye este Prg
DBMysql.prg
::nLastError==2014 // MySQL Command Out if Sync
Cuando el Servidor esta ocupado aqui atrapas el Error.
Me cuentas como te fue.
Saludos...


Attached files DBMySQL.prg (2.4 KB)Â