Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here





I have a Postgresql 7.2.1 database running on a linux environment..I am trying to connect to it from a VC++ program using PGDATABASE...

Actually, I am using one of the examples provided by on the libpq++ folder...

I build successfully all the libpq and libpq++ required files...

I changed everything on the code to connec to my db...I am adding to the Include folders the one specified on the Installation instructions, also I am attaching the libpqdll.lib and libpq++dll.lib libraries into the project...

I made the changes on the pg_hba.conf file, postmaster -i option and tcp/ip=true on the settings.

I am having the following error message when running the program:

Connection to Database failed:
Error returned: could not create socket: Either the application has not called WSAStartup or WSAStartup failed.

Any help is received...I am desperate!!!!:)

The code I am using is as follows:

        #include <iostream.h>
        #include <libpq++.h>                                    // libpq++ header file
        int main()
            char        state_code[3];                          // holds state code entered by user
            char        query_string[256];                      // holds constructed SQL query
            PgDatabase data("hostaddr= port=5432 dbname=paotest user=chris password=thompson");                     // connects to the database
            if ( data.ConnectionBad() )                         // did the database connection fail?
                cerr << "Connection to database failed." << endl
                     << "Error returned: " << data.ErrorMessage() << endl;
            //cout << "Enter a state code:  ";                    // prompt user for a state code
            //cin.get(state_code, 3, '\n');

            sprintf(query_string,                               // create an SQL query string
                    "SELECT * \
                     FROM people");

            if ( !data.ExecTuplesOk(query_string) )             // send the query
                cerr << "SELECT query failed." << endl;
            for (int i=0; i < data.Tuples(); i++)               // loop through all rows returned
                    cout << data.GetValue(i,0) << endl;         // print the value returned
            return 0;


Well, it looks like your client is running on windows?
If so, as the error message states, you must call WSAStartup. That initializes the socket library on your client. You should call WSACleanUp when done, to avoid system-widde memoryleaks.


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close