Bug #54955 #error 1040 Too many |Can not disconnect mysql connection manual use Connect/c++
Submitted: 2 Jul 2010 11:14 Modified: 5 Jul 2010 12:45
Reporter: sonly strong Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Connector / C++ Severity:S3 (Non-critical)
Version: OS:Windows (VS2008)
Assigned to: CPU Architecture:Any

[2 Jul 2010 11:14] sonly strong
Description:
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 

How to repeat:
UINT ThreadFun( void *pData )
{
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) 
{ 
		CString info=_T("");
		info.Format(_T("error code:%d"),e.getErrorCode());
		info+="sql state:";
		info+=e.getSQLState();
                AfxMessageBox(info);

}

The above is the thread function.

and I run the Multi-thread 

	for (int i=0;i<2000;i++)
	{
		AfxBeginThread(ThreadFun,NULL);
		Sleep(100);
	}

about some connection, I cannot insert data into the table.
show error:#error 1040 Too many connection.
[2 Jul 2010 12:23] Ulf Wendel
Server configuration matter not a driver issue.
[2 Jul 2010 12:26] sonly strong
I have set max_connections = 2000

the mysql connection do not close immediately.

con->close(); 
delete con; 
The code above dont really close the connection immediately.
[5 Jul 2010 6:57] Sveta Smirnova
Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://dev.mysql.com/doc/ and the instructions on
how to report a bug at http://bugs.mysql.com/how-to-report.php

See explanation in bug #54817
[5 Jul 2010 12:45] sonly strong
How can I use multi-thread with connector/c++?
Could you pls give me some info?