Autore Topic: Connessione MySQL caduta: come ristabilirla ?  (Letto 373 volte)

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.724
  • Ne mors quidem nos iunget
    • Mostra profilo
Connessione MySQL caduta: come ristabilirla ?
« il: 06 Settembre 2013, 09:15:14 »
Vi riporto questa discussione apparsa nella Mailing List ufficiale:


" We are connected to a MySQL database (on the local machine) and the
application sometimes runs for days/weeks and numerous select, update,
delete, etc are going over the connection every hour (so it isn't lack of
traffic).

We do things like:

Codice: gambas [Seleziona]
rResult = Main.hDB.Exec("UPDATE devices_alex SET value = &1 WHERE nodeid = &2", sValue, sAddress)

After a while (not easy reproduceable) we get errors like:
'Query failed: Lost connection to MySQL server during query'

Is there an easy way of forcing MySQL to reconnect again and retry the
command? This without adding many-many-many lines of code at each SQL Exec
statement.

Regards,
Alex
"


" There was a discussion of this in the forums a while ago.  It might help
to search the forum archives.

(Sorry I can't be more specific - I avoid MySQL like the plague!)
Bruce
"


" MySQL automatic reconnection is normally handled automatically by Gambas
for a while. Which version do you use?

--
Benoît Minisini
"


" Version 3.4.2 is used, and after reconnecting, the request will be retried
too? Currently i see an error thrown.

Alex
"


" This is a mysql client option.

When connecting to a mysql database, the Gambas mysql driver define the
MYSQL_OPT_RECONNECT option, that tells the mysql client to automatically
reconnect to the server if the connection is lost.

So normally you should not have the "connection lost" error message.

If, apparently, the mysql client does not respect its own options, you
will have to handle that yourself.

What I suggest is explicitly closing and reopening the connection from
time to time (for example each hour). I did that for my own application
because I got some errors too (but not the "connection lost" error,
something else) and I don't have problems anymore.

If you tell me that this solution works, maybe I will integrate it
directly into the database driver.

Regards,

--
Benoît Minisini
"


" Hi Benoît,

If you would integrate this into the database driver, then could this be
made:
1. Optional (so you can enable or disable the closing and reopening of
the connection)
2. With a configurable time interval that defaults to an hour for
example, but can be set to other intervals as well.

--
Kind regards,

Willy
"
« Ultima modifica: 06 Settembre 2013, 17:34:50 da vuott »
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »