Lost connection MySQL - Catch error

Lost connection MySQL - Catch error

Postby nlerdafehn » Thu May 13, 2021 9:06 pm

Good afternoon,

I was looking in the forum about how to handle it but I found different solutions to other problems but not to this.

The problem to be solved is how to deal with "Lost Connection to MYSQL" errors due to disconnection from the internet. I already use "Set TIMEOUT" and also the timer so that the connection is not cut off, but the problem lies with clients with WiFi networks, where, thanks to FiveWin for existing, when they have a micro-cut of a few seconds, it freezes for a couple of seconds and reconnect.

The problem is that when it tries to reconnect and does not do so in 15 seconds, it gives me a [b] Fatal Error [/ b] where the application has to be closed without any other way.

Is there a way to change that time or if the connection was lost, show a msgstop () and return to the previous screen so as not to lose all the load made up to that moment?

Process example:

When you press a button, a query is executed that brings up information. When you press it, it waits for the reconnection, if it does not reconnect within 15 seconds, it throws the "Lost Connection to MySQL" error and forces the user to exit.

It would be a very good tool to implement in all systems, since in Argentina the networks are not made by professionals and the hardware is of poor quality.

Thanks in advance!
Nicolás
nlerdafehn
 
Posts: 50
Joined: Tue Feb 02, 2021 10:21 pm
Location: Buenos Aires, Argentina

Re: Lost connection MySQL - Catch error

Postby nageswaragunupudi » Fri May 14, 2021 3:42 pm

it throws the "Lost Connection to MySQL" error

This is for information of the user, so that the user can take action to check the cables/internet connection and try the operation again.

and forces the user to exit

NO.
If the connection can not be established soon, the user can just click "OK" and continue with the program.
He can do all other operations with the data already read, like sorting, seeking, filtering, printing and anything except (1) read more data and (2) write any data to the server.
Again when the internet connection is restored, the user can resume working and the program automatically reconnects to the server and continues from where it left.

FWH library is the only library that silently reconnects and do not be misled by any postings in the forums by other users, using other libraries.
Regards

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

Re: Lost connection MySQL - Catch error

Postby nlerdafehn » Fri May 14, 2021 7:55 pm

Hello Mr. Rao,

When I press on the button, it executes a SELECT of products and show it.

Image

I tried to disconnect wire from the PC and give me this error:

Image

The user doesn't have any other choice than QUIT.

May be, because I use Dolphin? How can I change it?


nageswaragunupudi wrote:
it throws the "Lost Connection to MySQL" error

This is for information of the user, so that the user can take action to check the cables/internet connection and try the operation again.

and forces the user to exit

NO.
If the connection can not be established soon, the user can just click "OK" and continue with the program.
He can do all other operations with the data already read, like sorting, seeking, filtering, printing and anything except (1) read more data and (2) write any data to the server.
Again when the internet connection is restored, the user can resume working and the program automatically reconnects to the server and continues from where it left.

FWH library is the only library that silently reconnects and do not be misled by any postings in the forums by other users, using other libraries.
Nicolás
nlerdafehn
 
Posts: 50
Joined: Tue Feb 02, 2021 10:21 pm
Location: Buenos Aires, Argentina

Re: Lost connection MySQL - Catch error

Postby nageswaragunupudi » Fri May 14, 2021 11:21 pm

Oh, You are using Dolphin.

I thought you are using FWH built-in MariaDB library, which comes free along with FWH.
I was talking about the built-in library. You can consider using this library.
Regards

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

Re: Lost connection MySQL - Catch error

Postby nageswaragunupudi » Sat May 15, 2021 2:55 am

If you want to continue using Dolphin, then use your error block to catch this error and resume.
Please see this sample and implement in your own way:
Code: Select all  Expand view
function DolphinLostCn()

   local oCn, oQry
   local bErrFW
   local lCnErr := .f.

   bErrFW   := ERRORBLOCK()
   ERRORBLOCK( { |e| MyError( e, @lCnErr, bErrFW ) } )

   oCn   := FW_DemoDB( "DLP" ) // your connection here

   ? "Disconnect Server now"

   MsgRun( "Opening table", "STATES", { || oQry  := oCn:Query( "select * from states" ) } )
   if lCnErr
      lCnErr   := .f.
      ? "Can not open query. Lost connection"
   else
      XBROWSER oQry
   endif

   ? "Continue with other works"

   oQry:End()
   oCn:End()

return nil

function MyError( e, lCnErr, bErrFW )

   if HB_ISSTRING( e:SubSystem ) .and. e:SubSystem == "MYSQL" .and. ;
      HB_ISNUMERIC( e:SubCode ) .and. e:SubCode == 2013

      ? "Server disconnected"
      lCnErr   := .t.
      return .f.
   endif

return Eval( bErrFW, e )

 
Regards

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

Re: Lost connection MySQL - Catch error

Postby nlerdafehn » Tue May 18, 2021 6:25 pm

Thanks Mr. Rao for your answer.

I tried and it worked as a partial solution. If connection is not reconnected when it ask again for something, it give me another fatal error and quit.

Is there any way to implement ErrorBlock for mysql in general?

I tried this:

main:
Code: Select all  Expand view
ErrorBlock( { | oError | GetErrorInfo( oError ) } )


Code: Select all  Expand view
********************
function GetErrorInfo( oError )
*********************
 
   local cInfo := "", n

   if oError:sUbsystem = "MYSQL" .and. oError:sUbcode = 2013
    msginfo("Se perdio la conexión al servidor","Ha ocurrido un error de conexion")
    return .t.
   endif

   cInfo += "SubSystem: " + oError:sUbsystem + Chr( 13 ) + Chr( 10 )
   cInfo += "SubCode: " + AllTrim(Str(oError:sUbcode) ) + Chr( 13 ) + Chr( 10 )
   cInfo += "Description: " + oError:Description + Chr( 13 ) + Chr( 10 )
   cInfo += "GenCode: " + AllTrim( Str( oError:genCode ) ) + Chr( 13 ) + Chr( 10 )
   cInfo += "Operation: " + oError:Operation + Chr( 13 ) + Chr( 10 )
 
   if ValType( oError:Args ) == "A"
      for n = 1 to Len( oError:Args )
          cInfo += "Args[" + AllTrim( Str( n ) ) + "] " + ;
                   cValToChar( oError:Args[ n ] ) + Chr( 13 ) + Chr( 10 )
      next
   endif
 
   n = 2
   while ! Empty( ProcName( n ) )
      cInfo += ProcName( n ) + "(" + AllTrim( Str( ProcLine( n++ ) ) ) + ")" + Chr( 13 ) + Chr( 10 )
   end

   msginfo(cInfo,"Ha ocurrido un error")
 
return .t.


There is a problem with this code. First of all, It runs twice. Always. I don't know why. Second, I want to use FW error handler for any other error that is not MySQL. And with this I overwrite FW function of Errorblock. And last one, when I try to try again same function, I have an error of MySQL 1096 of "No tables in use" and after that, I try again and works as normal.

But, If I want to run the function and there is no connection it stop working and windows quit the application.

Do you have any clue? Thanks in advance!
Nicolás
nlerdafehn
 
Posts: 50
Joined: Tue Feb 02, 2021 10:21 pm
Location: Buenos Aires, Argentina


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 26 guests