Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PGDATABASE ERROR!!!...URGENT!!!!!!! 1

Status
Not open for further replies.

pgomezsa

Programmer
Oct 24, 2002
7
0
0
US
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(&quot;hostaddr=10.0.20.45 port=5432 dbname=paotest user=chris password=thompson&quot;); // connects to the database

if ( data.ConnectionBad() ) // did the database connection fail?
{
cerr << &quot;Connection to database failed.&quot; << endl
<< &quot;Error returned: &quot; << data.ErrorMessage() << endl;
exit(1);
}

//cout << &quot;Enter a state code: &quot;; // prompt user for a state code
//cin.get(state_code, 3, '\n');

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

if ( !data.ExecTuplesOk(query_string) ) // send the query
{
cerr << &quot;SELECT query failed.&quot; << 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;
}

 
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.

/Björn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top