Trouble connecting to PostgreSQL database using libpqxx


I am using a simple C++ console app to communicate with a PostgreSQL 13 database. To do so, I use the libpqxx 7.3.1, and get some trouble when trying to connect to the database. Here is my code :

#include <iostream>
#include <pqxx/pqxx>

int main() {
    try {
        pqxx::connection c{ "postgresql://postgres:password@localhost/database_test" };
        if (c.is_open()) {
            std::cout << "Opened database successfully: " << c.dbname() << std::endl;
        else {
            std::cout << "Can't open database" << std::endl;
            return 1;
    catch (const std::exception& e) {
        std::cerr << e.what() << std::endl;

There is no problem during compilation, but when the program is executed, it returns this error, which is not detected by the try/catch :

Exception lifted to 0x00007FFA508B0157 (pqxx.dll) in ConsoleApplication1.exe: 0xC0000005: Access violation when reading location 0x0000000000000010.

In the console, I get the cout "Opened database successfully: database_test" but in the msg of the error seems to close the connection : 0x00007ffa508d7928 "Closing connection with outstanding receivers.".

I am new to C++ and PostgreSQL, I don't know why this error is not caught, and why does it occur. Is there anyone who can help me?

asked on Stack Overflow May 19, 2021 by alagache

0 Answers

Nobody has answered this question yet.

User contributions licensed under CC BY-SA 3.0