sql - 无法从 C 连接到数据库

标签 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

我该如何解决这个问题?

谢谢

最佳答案

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

我添加了这些行

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

并且成功了。

关于sql - 无法从 C 连接到数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33804498/

相关文章:

javascript - PostgreSQL docker-compose down 后使用的端口不能再使用

python - Postgres : Retrieve records Sequentially at 5 seconds interval

mysql select between two dates 有奇怪的行为

php - ionic 2 : marge details with same values

MySQL无需停机即可更新整个数据库

c - FILE IO,标记字符串

sql - Postgres 查询中的语法错误

sql - Psql not null 错误但值不为空

c - C 中的递归堆栈

c - 错误 : expected expression before 'unsigned'