无法从C连接到数据库

时间:2015-11-19 12:50:31

标签: sql c postgresql

我编写了一个连接SQL数据库的函数

void Test(){                        

    PGconn *conn;
    PGresult *res;
    conn = PQconnectdb("dbname=metocean host=try user=Test password=test");

    fprintf(stderr, "Connection to database failed: %s", PQerrorMessage(conn));
}

我在for循环中调用它并且它在某些循环中工作正常,但过了一段时间我得到了错误

Connection to database failed: could not create socket: Too many open files

我该如何解决这个问题?

由于

1 个答案:

答案 0 :(得分:0)

我已经解决了关闭连接的问题。

我添加了行

    res = PQexec(conn, "CLOSE myportal");
    PQclear(res);
    PQfinish(conn);

并且有效。

相关问题