MySQL Forums
Forum List  »  Connector/C++

MySQL Connection State
Posted by: Saleem Khan
Date: August 22, 2008 04:37AM

Hi,

The version of MySQL is 4.1.7 and platform is Redhat Linux.

I would like to know what would be an ideal mysql client api to find out the MySQL connection is up or not. I require this to implement a reconnection logic in my application when ever there is a MySQL Server is down or there is any network issues. It means this will keep trying till the MySQL Server comes up and work normally as before the connection was down.

Curretly I am using mysql_stat to do this but i am getting into trouble with the command out of sync and my application crashing. Can some body suggest an alternative to this or using this in a proper manner. This i tried to implement similar to ADO objects State. Is this correct?.

int A::State()
{
mysql_stat(&m_mysql);
unsigned int ui_mysqlerrorno = mysql_errno(&m_mysql);
int iRet = 0;
switch (ui_mysqlerrorno)
{
case CR_COMMANDS_OUT_OF_SYNC:
iRet = COMMANDS_OUT_OF_SYNC;
break;
case CR_SERVER_GONE_ERROR:
iRet = SERVER_GONE_ERROR;
break;
case CR_SERVER_LOST :
iRet = SERVER_LOST;
break;
case CR_UNKNOWN_ERROR:
iRet = UNKNOWN_ERROR;
break;
default:
break;
}
return iRet;
}



Edited 1 time(s). Last edit at 08/22/2008 04:37AM by Saleem Khan.

Options: ReplyQuote


Subject
Views
Written By
Posted
MySQL Connection State
6854
August 22, 2008 04:37AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.