|
我试着用 Postgresql 做数据库,可是当我连接时却提示下面的错误:
Connection to host=localhost dbname=template1 failed, could not connect to server: Network is unreachable
Is the server running on host localhost and accepting
TCP/IP connections on port 5432?
是不是端口有问题啊?我该怎么设置呢?源码如下,多谢!!!
#include <stdlib.h>
#include <stdio.h>
#include <libpq-fe.h>
int main()
{
PGconn *conn;
const char *connection_str = "host=localhost dbname=template1";
conn = PQconnectdb(connection_str);
if (PQstatus(conn) == CONNECTION_BAD)
{ fprintf(stderr,"Connection to %s failed, %s",connection_str,PQerrorMessage(conn));}
else
{ printf("Connected OK\n");}
PQfinish(conn);
return EXIT_SUCCESS;
} |
|