Index: connection.cpp
===================================================================
--- connection.cpp	(revision 7577)
+++ connection.cpp	(working copy)
@@ -169,16 +169,18 @@
         newConn->prev = lastConn;
         lastConn->next = newConn;
     }
-    else if (connStr.IsEmpty())
-    {
-        LogMessage(wxString::Format(_("Failed to create new connection to database %s"), db.c_str()), LOG_WARNING);
-        LogMessage(wxString::Format(_("\tError message from connection : (%s)"), newConn->GetLastError().c_str()), LOG_WARNING);
-        return NULL;
-    }
     else
     {
-        LogMessage(wxString::Format(_("Failed to create new connection for connection string: %s"), connStr.c_str()), LOG_WARNING);
-        LogMessage(wxString::Format(_("\tError message from connection : (%s)"), newConn->GetLastError().c_str()), LOG_WARNING);
+        wxString warnMsg;
+        if (connStr.IsEmpty())
+            warnMsg
+              = wxString::Format(_("Failed to create new connection to database '%s':'%s'"),
+                                        db.c_str(), newConn->GetLastError().c_str());
+        else
+            warnMsg
+              = wxString::Format(_("Failed to create new connection for connection string '%s':%s"),
+                                        connStr.c_str(), newConn->GetLastError().c_str());
+        LogMessage(warnMsg, LOG_WARN_EXT);
         return NULL;
     }
 
Index: include/pgAgent.h
===================================================================
--- include/pgAgent.h	(revision 7577)
+++ include/pgAgent.h	(working copy)
@@ -39,7 +39,12 @@
 {
 	LOG_ERROR = 0,
 	LOG_WARNING,
-	LOG_DEBUG
+	LOG_DEBUG,
+	// NOTE:
+	//     "EXTENDED WARNING" will be used to log message for any LogLevel
+    //     Use it, only when initializing the pgAgent and to log error in
+    //     connection
+	LOG_WARN_EXT = 15
 };
 
 // Prototypes
Index: win32.cpp
===================================================================
--- win32.cpp	(revision 7577)
+++ win32.cpp	(working copy)
@@ -72,6 +72,10 @@
                 ReportEvent(eventHandle, EVENTLOG_ERROR_TYPE, 0, 0, NULL, 1, 0, tmp, NULL);
                 exit(1);
                 break;
+            // Log the message as warning (for any LogLevel)
+            case LOG_WARN_EXT:
+                ReportEvent(eventHandle, EVENTLOG_WARNING_TYPE, 0, 0, NULL, 1, 0, tmp, NULL);
+                break;
         }
     }
     else
@@ -90,6 +94,10 @@
                 wxPrintf(_("ERROR: %s\n"), msg);
                 exit(1);
                 break;
+            // Log the message as warning
+            case LOG_WARN_EXT:
+                wxPrintf(_("WARNING: %s\n"), msg);
+                break;
         }
     }
 }
Index: unix.cpp
===================================================================
--- unix.cpp	(revision 7577)
+++ unix.cpp	(working copy)
@@ -64,6 +64,9 @@
         file.Write(_("ERROR: ") + msg + wxT("\n"));
         exit(1);
         break;
+    case LOG_WARN_EXT:
+        file.Write(_("WARNING: ") + msg + wxT("\n"));
+        break;
     }
 
     if (logFile.IsEmpty())
Index: pgAgent.cpp
===================================================================
--- pgAgent.cpp	(revision 7577)
+++ pgAgent.cpp	(working copy)
@@ -1,4 +1,4 @@
-//////////////////////////////////////////////////////////////////////////
+
 //
 // pgAgent - PostgreSQL Tools
 // $Id: pgAgent.cpp 4875 2006-01-06 21:06:46Z dpage $
@@ -22,6 +22,8 @@
 long shortWait=10;
 long minLogLevel=LOG_ERROR;
 
+#define MAXATTEMPT 10
+
 #ifndef __WXMSW__
 bool runInForeground = false;
 wxString logFile = wxEmptyString;
@@ -125,6 +127,7 @@
 
 void MainLoop()
 {
+    int attemptCount = 1;
     // OK, let's get down to business
     do
     {
@@ -194,8 +197,14 @@
             MainRestartLoop(serviceConn);
         }
 
-        LogMessage(wxString::Format(_("Couldn't create connection: %s"), serviceConn->GetLastError().c_str()), LOG_WARNING);
+        LogMessage(wxString::Format(_("ATTEMPT:%d:Couldn't create the primary connection:REASON:%s"), attemptCount, serviceConn->GetLastError().c_str()), LOG_WARN_EXT);
         DBconn::ClearConnections(true);
+
+        // Try establishing primary connection upto MAXATTEMPT times
+        if (attemptCount++ >= (int)MAXATTEMPT)
+        {
+            LogMessage(wxString::Format(_("Stopping pgAgent: Couldn't establish the primary connection with the postgresql database server.")), LOG_ERROR);
+        }
         WaitAWhile(true);
     }
     while (1);
