Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search archives
  Advanced Search

Maintaining connectivity/failing gracefully when my application is connected to a PostgreSQL server over Wi-fi on a PDT/PDA handset


  • From: Peter Geoghegan <peter(dot)geoghegan86(at)gmail(dot)com>
  • To: pgsql-general(at)postgresql(dot)org
  • Subject: Maintaining connectivity/failing gracefully when my application is connected to a PostgreSQL server over Wi-fi on a PDT/PDA handset
  • Date: Thu, 30 Apr 2009 09:25:25 +0100
  • Message-id: <db471ace0904300125q53e0e12cq94629caedf72c83b@mail.gmail.com> <text/plain>

Hello,

I'm developing a PostgreSQL application for Windows CE 5 on a PDT/ PDA
in C++/Qt, using Hiroshi Saito's libpq port for that platform. Since
the connection is established over wi-fi, and wi-fi connectivity is
often flaky, I feel that I have to "fail gracefully" to as great an
extent as possible. The following utility function,
VerifyDbConnection(), is called before every piece of database work:

void MainInterface::VerifyDbConnection()
{
   if (PQstatus(conn) != CONNECTION_OK)
   {
               for(;;)
               {
                       PQreset(conn);
                       if(PQstatus(conn) == CONNECTION_OK)
                               return;

                       QMessageBox msgbox_connection_lost;
                       msgbox_connection_lost.setText("Connection to
the database is lost, and cannot be re-established. "
                               "This may be due to the fact that
you're too far away from the Wi-fi access point, or because "
                               "the backoffice computer is turned off,
or it may be a low level connectivity problem." );
                       QPushButton* retry_button =
msgbox_connection_lost.addButton(tr("Reconnect"),
QMessageBox::ActionRole);
                       QPushButton* exit_button =
msgbox_connection_lost.addButton(tr("Exit"), QMessageBox::ActionRole);
                       msgbox_connection_lost.setWindowTitle("Connection lost");
                       msgbox_connection_lost.exec();

                       if(msgbox_connection_lost.clickedButton() ==
retry_button)
                       {
                               continue;
                       }
                       else if(msgbox_connection_lost.clickedButton()
== exit_button)
                       {
                               exit(0);
                               return;
                       }
               }
   }

}

This seemed to work fine initially; I'd abruptly stop the database
server, and I would see a messagebox informing me of a connectivity
problem. Then, I'd start the server, click the retry button, and have
connectivity restored. However, when I walk out of range of the wi-fi
access point, which is the probable cause of losing connectivity in
the real world, my program crashes without displaying an error message
(I would expect to see a visual C++ runtime error message).

Can someone suggest a reason for this, or a workaround?

Regards,
Peter Geoghegan



Home | Main Index | Thread Index

Privacy Policy | About PostgreSQL
Copyright © 1996 – 2012 PostgreSQL Global Development Group