MySQL Server has gone away

Forum related to MySQL

Moderators: gto, cipto_kh, EgonHugeist

Post Reply
Pitr
Fresh Boarder
Fresh Boarder
Posts: 1
Joined: 31.12.2008, 09:16

MySQL Server has gone away

Post by Pitr »

Hi everybody.
I'm using MySQL server and ZEOS components (C++ Builder 2007) to connect to it. Because client is connecting to the server via internet, there is a possibility, that server can be ocasionally unreachable.
Is there any way how to chceck if server is available?
Thanks for help.
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post by mdaems »

ZConnection.Pingserver

I wouldn't use it before every statement as it adds some overhead. More like something you do between pressing a button and starting some datatbase operation.

The function also attempts an automatic reconnect.

Mark
Image
skydvrz
Fresh Boarder
Fresh Boarder
Posts: 13
Joined: 15.12.2005, 22:56
Location: Olympia, WA USA
Contact:

Post by skydvrz »

I do something similar to mdaems, only I make it a little more useful.

Instead of a simple ping, I attempt to update a "sessions" table with the IP, hostname, login name, time of day at the server, version number, Etc. of the user. I have the sessions table update method activate on a 30 second timer.

Use the workstation hostname as a primary key to sort things out, and use an "on duplicate key" clause to simply update on insert collisions.

If the session update fails, then you know you've lost the connection and can light up an LED, pop a warning dialog box or retry opening the connection.

Using this system, I can then monitor who is online at any given time. I use a grid that refreshes every 30 seconds on a timer. This grid can be in the application itself or in an administrators utility app.

Just look for session records newer than 30 seconds old and display them in the sessions grid.

It comes in handy if I need to kick everyone off the server for maintenance. Its easier than using the MySQL Admin utility, since the session-watcher grid is application-specific and can include other user information.

Last, I can see in the session table who hasn't been online in weeks and review their access privs to the system.

HTH!

Kevin G. McCoy
Post Reply