[问题]C语言编程连接 PostgreSQL出现问题

Web、Mail、Ftp、DNS、Proxy、VPN、Samba、LDAP 等基础网络服务
回复
eric_win
帖子: 5
注册时间: 2007-04-05 14:25

[问题]C语言编程连接 PostgreSQL出现问题

#1

帖子 eric_win » 2007-05-13 13:11

我是新手刚接触postgresql 编程
系统是 ubuntu 6.06LTS
安装了 postgresql 8.1.9 默认设置
用户名 postgres 密码111
程序如下
#include <stdio.h>
#include <stdlib.h>
#include <postgresql/libpq-fe.h>

int main()
{
PGconn *conn;
const char *str = "host=localhost dbname=mydb";

conn = PQconnectdb(str);

if(PQstatus(conn) == CONNECTION_BAD){
fprintf(stderr,"Connection to %s failed,%s",str,PQerrorMessage(conn));
}else{
printf("Connection success");
}

PQfinish(conn);
return EXIT_SUCCESS;
}
运行出错信息
Connection to host=localhost dbname=mydb failed,fe_sendauth: no password supplied

把str改成 host=localhost dbname=mydb user=postgres password=111
之后 出错信息
Connection to host=localhost dbname=mydb user=postgres password=111 failed,致命错误: 用户 "postgres" Password 认证失败

请高手指点下
jerod
帖子: 5
注册时间: 2006-04-16 20:59

#2

帖子 jerod » 2007-05-18 16:13

注意在 postgresql 的安装目录下,有个pg_hba的文件,是用来设置访问权限的。还有一个文件叫... ,我记不太清了,在同一个目录下。也是设置权限的。同时,启动数据库时,好象用 '-i' 参数来打开TCP的。你都要查一下。
头像
forrid
帖子: 659
注册时间: 2007-04-23 17:40

#3

帖子 forrid » 2007-06-29 20:22

编辑postgresql.conf文件,修改以下代码:

代码: 全选

listen_address = '*' 
password_encryption = on
编辑pg_hba.conf,修改以下代码:

代码: 全选

local    all    all    trust
local    all    all    md5
重启PostgreSQL即可。

吾生也有涯,而知也无涯,以有涯随无涯,SB啊~~~~~~~~~~
回复