Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6706661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:32:48+00:00 2026-05-26T07:32:48+00:00

I am using libpqxx to connect to a postgres database by creating a class.

  • 0

I am using libpqxx to connect to a postgres database by creating a class.

class databaseConnection
{
public:
    pqxx::connection* conn;
    void SetConnection(){
        conn=new pqxx::connection(
            "username=temp "
            "host=db.corral.tacc.utexas.edu "
            "password=timelione "
            "dbname=temp");

    }

    void Disconnect(){
        conn->disconnect();
    }

    pqxx::result query(std::string strSQL){
        //SetConnection();
        pqxx::work trans(*conn,"trans");

        pqxx::result res=trans.exec(strSQL);

        trans.commit();
        return res;
    }
};

int main()
{
    databaseConnection* pdatabase;
    pdatabase->SetConnection();
    return 0;
}

I am getting error that says

terminate called after throwing an instance of 'pqxx::broken_connection' 
what(): invalid connection option "database"

Can anyone help me out?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:32:49+00:00Added an answer on May 26, 2026 at 7:32 am

    pgxx::connection(const PGSTD::string&) is basically a wrapper around libpq’s PQconnectdb() function, so the supported connection parameter keywords are the same as for libpq.

    The parameter key word for the PostgreSQL user name to connect as is user, not username. Perhaps correcting that will fix the problem.

    Also, in your sample code, pdatabase is an uninitialized pointer. You could either allocate a databaseConnection object on the stack with:

    databaseConnection database;
    database.SetConnection();
    

    or use new to heap-allocate a databaseConnection object:

    databaseConnection* pdatabase = new databaseConnection();
    pdatabase->SetConnection();
    

    But you need to pick one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using the following code: public class Panel extends SurfaceView { // ...... // in
Using TFS 2010. Creating a new query and in the filters added a comparison
Using C#, I need a class called User that has a username, password, active
I'm trying to implement a Search-Function using c++ and libpqxx. But I've got the
I want to create a test environment where the basic underlying postgres database is
Using boost python I need create nested namespace. Assume I have following cpp class
Using online interfaces to a version control system is a nice way to have
Using PyObjC , you can use Python to write Cocoa applications for OS X.
Using ASP.NET MVC there are situations (such as form submission) that may require a
Using C# .NET 3.5 and WCF, I'm trying to write out some of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.