  				{
  					/* We are done with authentication exchange */
  					conn->status = CONNECTION_AUTH_OK;
-@@ -1725,6 +1751,8 @@
+@@ -1725,6 +1752,8 @@
  					if (res->resultStatus != PGRES_FATAL_ERROR)
  						printfPQExpBuffer(&conn->errorMessage,
  										  libpq_gettext("unexpected message from server during startup\n"));

+    PQerrorCode               = _PQerrorCode
diff -urN postgresql-8.2.3/src/interfaces/libpq/exports.txt postgresql-8.2.3-tsnorri/src/interfaces/libpq/exports.txt
--- postgresql-8.2.3/src/interfaces/libpq/exports.txt	2006-08-18 22:52:39.000000000 +0300
+++ postgresql-8.2.3-tsnorri/src/interfaces/libpq/exports.txt	2007-03-01 16:15:46.000000000 +0200
@@ -136,3 +136,5 @@
 PQdescribePortal          134
 PQsendDescribePrepared    135

 								   conn->errorMessage.data) != STATUS_OK)
 				{
 					conn->errorMessage.len = strlen(conn->errorMessage.data);
+                    conn->errorCode = PGCONN_AUTH_FAILURE;
 					goto error_return;
 				}
 				conn->errorMessage.len = strlen(conn->errorMessage.data);
@@ -1680,7 +1707,7 @@
 				if (pqFlush(conn))
 					goto error_return;
 
