LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 707|回复: 0

连接Postgresql时遇到的问题!

[复制链接]
发表于 2003-3-7 20:13:02 | 显示全部楼层 |阅读模式
我试着用 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;
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表