Mysql with ADO

Mysql with ADO

Postby Maurizio » Fri Oct 26, 2018 6:34 am

Hello Rao

I use Mysql via ADO with the functions of adofuncs.prg

when the program stays idle for a while, with the reuse I have this error

Error FW_OpenRecordSet(440)

Code: Select all  Expand view  RUN
function FW_OpenRecordSet( oCn, cSql, nLockType, nCursorType, nMaxRecords, nOpt )
.
.

CATCH
         if ! Empty( oCn )
            FW_ShowAdoError( oCn )       <-------- Line 440
         endif
         oRs   := nil
      END


I think the problem is with the timeout of Mysql .
I saw that this problem was solved with MariaDB ,
Is it possible to solve this problem in ADO (adofuns.prg ) ?

Thanks
Maurizio
User avatar
Maurizio
 
Posts: 825
Joined: Mon Oct 10, 2005 1:29 pm

Re: Mysql with ADO

Postby nageswaragunupudi » Sun Oct 28, 2018 4:13 pm

Our friend Mr. Anser also uses MySql with ADO. He developed his own technique to handle the timeout issues. It would be better if Mr. Anser explains his approach.
Regards

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

Re: Mysql with ADO

Postby anserkk » Mon Oct 29, 2018 4:34 am

Yes, we will definitely will face this issue at one point of time, especially when we access the database via Internet. At times, the internet connectivity in the client PC may break. It may be for few seconds or for few minutes, or hours and the internet connectivity is resrored automatically.

There are few methods, like increasing the wait_timeout session variable etc.

I followed the following method which is working fine for me for many years

All my database queries passes thru a single function that I have created. This function will check the present connectivity status, If the connectivity is fine, then proceed with the query, OR else it will reconnect to the database and then process the query. Then return the result set.

I use Stored procedures extensively for insert/update/delete etc. I make use of the above said function to handle such situations too.
User avatar
anserkk
 
Posts: 1333
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: Mysql with ADO

Postby nageswaragunupudi » Mon Oct 29, 2018 4:37 am

How do you check if the connection is live or not?
Regards

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

Re: Mysql with ADO

Postby anserkk » Mon Oct 29, 2018 5:12 am

I check whether the connection object is NIL or not
if not NIL, then I check whether the DefaultDatabase property (available in the connection object) is empty or NOT, if empty, then I understand that for some reason, the connection with the database was lost in-between and need to reconnect. Then I call the function to Connect to the Database
User avatar
anserkk
 
Posts: 1333
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: Mysql with ADO

Postby cnavarro » Mon Oct 29, 2018 9:00 am

anserkk wrote:I check whether the connection object is NIL or not
if not NIL, then I check whether the DefaultDatabase property (available in the connection object) is empty or NOT, if empty, then I understand that for some reason, the connection with the database was lost in-between and need to reconnect. Then I call the function to Connect to the Database


Hello Anserk
And, it is not valid and sufficient to verify that oCn:State > 0 ( or oRs:State > 0 ) ?
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6549
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Mysql with ADO

Postby anserkk » Mon Oct 29, 2018 9:32 am

cnavarro wrote:Hello Anserk
And, it is not valid and sufficient to verify that oCn:State > 0 ( or oRs:State > 0 ) ?


If I am not wrong, oCn:State was giving me wrong results even if the internet was disconnected. Internet may get disconnected and get connected again (especially low cost broadband connections), may be in few seconds it gets reconnected again without any user intervention, but if you try to do some operation on the database, even after the connectivity is re-established, it was giving problems. May be the MySQL server will not allow any operation by a client that got disconnected in between
User avatar
anserkk
 
Posts: 1333
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: Mysql with ADO

Postby nageswaragunupudi » Mon Oct 29, 2018 3:11 pm

Suggested function:
Code: Select all  Expand view  RUN
function IsCnActive( oCn )

   if oCn:State == 0 .or. Empty( oCn:Properties( "Current Catalog" ):Value )
      oCn:Close()
      oCn:Open()
   endif

return oCn:State > 0
 

This function returns if the connection is still active or not. In case connection is lost for some reason, this function tries to reconnect before returning the result.

Usage:

Code: Select all  Expand view  RUN

if IsCnActive( oCn )
    < ANY ACTION WITH ADO >
else
    ? "connection lost. Check your connection and try again"
endif
 

Welcome comments and suggestions.
Regards

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

Re: Mysql with ADO

Postby anserkk » Tue Oct 30, 2018 4:12 am

This looks like a good solution.
User avatar
anserkk
 
Posts: 1333
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: Mysql with ADO

Postby Maurizio » Tue Oct 30, 2018 7:06 am

Thanks Rao , Anser,Navarro

I try and let you know .

Maurizio
User avatar
Maurizio
 
Posts: 825
Joined: Mon Oct 10, 2005 1:29 pm

Re: Mysql with ADO

Postby nageswaragunupudi » Tue Oct 30, 2018 8:26 am

Another approach
Code: Select all  Expand view  RUN
function AdoExecute( oCn, bAction )

   local uRet
   
   if oCn:State == 0 .or. Empty( oCn:Properties( "Current Catalog" ):Value )
      oCn:Close()
      oCn:Open()
   endif
   if oCn:State > 0
      TRY
         uRet  := Eval( bAction, oCn )
      CATCH
         FW_ShowAdoError( oCn )
      END
   else
      ? "Connection Lost. Check your connection"
   endif

return uRet


//Usage:

oRs      := AdoExecute( oMyConObject, { |oCn| FW_OpenRecordSet( oCn, cSql ) } )
uResult  := AdoExecute( oMyConObject, { |oCn| oCn:Execute( cSql ) } )
 
Regards

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

Re: Mysql with ADO

Postby leandro » Fri Aug 11, 2023 10:28 am

Hola buenos días,

Retomando este tema, estamos usando el código que alguna vez publico Mr. Rao, para poder hacer la reconexión remota a las bases de datos de mysql vía ADO. Pero desde hace unos días cuando actualizamos la versión FWH2307, nos esta devolviendo varios errores, los cuales publico aqui para ver si alguien a podido realizar la reconexión con las bases de datos, o si ya existe una función con ADO que se encargue de la reconexión.

Code: Select all  Expand view  RUN
Function AdoExecute( oCn, bAction ) //Aporte Mr.Rao Foro FW
Local uRet
if oCn:State == 0 .or. Empty( oCn:Properties( "Current Catalog" ):Value )
    oCn:Close()
    oCn:Open()
endif
if oCn:State > 0
    TRY
        uRet  := Eval( bAction, oCn )
    CATCH
        FW_ShowAdoError( oCn )
    END
else
    msginfo("Conexión Perdida, imposible recuperar","Error de conexión")
endif
//Usage:
//oRs      := AdoExecute( oMyConObject, { |oCn| FW_OpenRecordSet( oCn, cSql ) } )
//uResult  := AdoExecute( oMyConObject, { |oCn| oCn:Execute( cSql ) } )
return uRet


Image
Image
Saludos
LEANDRO AREVALO
Bogotá (Colombia)
https://hymlyma.com
https://hymplus.com/
leandroalfonso111@gmail.com
leandroalfonso111@hotmail.com

[ Embarcadero C++ 7.60 for Win32 ] [ FiveWin 23.07 ] [ xHarbour 1.3.0 Intl. (SimpLex) (Build 20230914) ]
User avatar
leandro
 
Posts: 1676
Joined: Wed Oct 26, 2005 2:49 pm
Location: Colombia


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 73 guests