我编写了一个连接到 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/