Hi...
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=10.0.20.45 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;
exit(1);
}
//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;
exit(1);
}
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;
}
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=10.0.20.45 port=5432 dbname=paotest user=chris password=thompson"
if ( data.ConnectionBad() ) // did the database connection fail?
{
cerr << "Connection to database failed." << endl
<< "Error returned: " << data.ErrorMessage() << endl;
exit(1);
}
//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;
exit(1);
}
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;
}