Frage

I have installed postgresql9.2.4 in my win7 laptop and have wrote a simple program to test the connection in my vs2008.The code is here:

#include "stdafx.h"
#include <windows.h>
#include "libpq-fe.h"


int _tmain(int argc, _TCHAR* argv[])
{
    const char *conninfo;
    PGconn     *conn;

    conninfo = "password = password";

    conn = PQconnectdb(conninfo);

    if (PQstatus(conn) != CONNECTION_OK)
    {
        printf("Connection to database failed: %s",
                PQerrorMessage(conn));
    }

    system("pause");
    return 0;
}

It showed an error that about authentication fail after ran it. I know it was the fault about password, it shoulded be md5 encrypted.So I searched in google.There almost no issue about this problem.I found a head file named "md5.h" in libpq folder and has a function named "pg_md5_hash", I tried it and came with many link error. Can anyone give me some suggestions? Thanks.

War es hilfreich?

Lösung

You don't have to encrypt password by yourself. Libpq is choosing authentication method depending on pg_hba.conf configuration.

Your conninfo is far from proper. You provided password, but you missed at least database and user name.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top