Search code examples
c++databasepostgresqlwt

Exception during connecting to postgresql database using wt c++ library?


I`m trying to connect to postgresql database which name is "galaxydatabase" and I encountered an unhandled exception. Source code:

#include <Wt/Dbo/Dbo>
#include <Wt/Dbo/backend/Postgres>

namespace dbo = Wt::Dbo;

void run()
{
    dbo::backend::Postgres po;
    po.connect("galaxydatabase");
    // or
    //dbo::backend::Postgres po("galaxydatabase"); // the same exception???
}

int main(int argc, char **argv)
{
    run();
}

enter image description here


Solution

  • connect() expects a PostgreSQL connection string, e.g. "host=127.0.0.1 user=test password=test port=5432 dbname=test". You can provide different parameters as needed, leave out what is not needed.

    The PostgreSQL documentation has more on what parameters are allowed and what they do.