Quantcast
Channel: MySQL Forums - Connector/C++
Viewing all articles
Browse latest Browse all 527

#error 1040, Too many connections, How to disconnect mysql connection manual use Connect/c++? (1 reply)

$
0
0
I want to Insert mass data into Mysql by multi-thread in Windows.
It shows #error 1040, Too many connections

I set the
max_connections = 1000 in my.ini

after run 1000 thead, insert 1000 data into mysql, I cannot insert more.
and I use "netstat -an" check the port stats.
show a lots of
TCP 127.0.0.1:3306 127.0.0.1:1160 ESTABLISHED
TCP 127.0.0.1:3306 127.0.0.1:1163 ESTABLISHED
TCP 127.0.0.1:3306 127.0.0.1:1166 ESTABLISHED
TCP 127.0.0.1:3306 127.0.0.1:1169 ESTABLISHED
TCP 127.0.0.1:3306 127.0.0.1:1172 ESTABLISHED
TCP 127.0.0.1:3306 127.0.0.1:1175 ESTABLISHED
TCP 127.0.0.1:3306 127.0.0.1:1178 ESTABLISHED
TCP 127.0.0.1:3306 127.0.0.1:1181 ESTABLISHED
TCP 127.0.0.1:3306 127.0.0.1:1184 ESTABLISHED

and

TCP 127.0.0.1:4879 127.0.0.1:3306 TIME_WAIT
TCP 127.0.0.1:4882 127.0.0.1:3306 TIME_WAIT
TCP 127.0.0.1:4887 127.0.0.1:3306 TIME_WAIT
TCP 127.0.0.1:4890 127.0.0.1:3306 TIME_WAIT
TCP 127.0.0.1:4893 127.0.0.1:3306 TIME_WAIT
TCP 127.0.0.1:4898 127.0.0.1:3306 TIME_WAIT
TCP 127.0.0.1:4901 127.0.0.1:3306 TIME_WAIT
TCP 127.0.0.1:4905 127.0.0.1:3306 TIME_WAIT

I need to disconnect immediately when I finished the thead. How can I do?
If I use the c API, Can use the mysql_close(&mysql);
But I dont know how to use the Connect/c++ to close the connection


try
{
sql::Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
sql::ResultSet *res;

/* Create a connection */
driver = get_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "root", "root");
/* Connect to the MySQL test database */
con->setSchema("test");

stmt = con->createStatement();
res = stmt->executeQuery("insert data sql here.............");
}
delete res;
delete stmt;
con->close();
delete con;

}
catch (sql::SQLException &e)
{
;
}

Viewing all articles
Browse latest Browse all 527

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>