mysql too many connections

昝辉Zac Zac的SEO博客,坚持12年,优化成为生活。

mysql too many connections

解决办法:

1.在使用MYSQL数据源的地方加入try/catch/finally

2.检查MySqlConnection使用后是否有做close()

3.不要把MysqlConnection连接弄成 static 的,每次连接都创建一个新的连接.

程序代码如下:

  1. MySql.Data.MySqlClient.MySqlConnectionmysqlConnection=newMySqlConnection(SDS.SMS.DAL.SqlHelper.strSMS);
  2. mysqlConnection.Open();
  3. stringselectCommand="selectid,model,number,brand,sendtime,pubdate,autoinsert_flag,mobilephonefromtbl_saledatawhereautoinsert_flag=0andsendtime='"+date+"'";
  4. try
  5. {
  6. IListIlst=newList();
  7. using(MySqlDataReaderdr=MySql.Data.MySqlClient.MySqlHelper.ExecuteReader(SDS.SMS.DAL.SqlHelper.strSMS,selectCommand))
  8. {
  9. while(dr.Read())
  10. {
  11. Ilst.Add(Populater(dr));
  12. }
  13. returnIlst;
  14. //关闭
  15. dr.Close();
  16. mysqlConnection.Close();
  17. }
  18. }
  19. catch(Exceptione)
  20. {
  21. throwe;
  22. }
  23. finally
  24. {
  25. mysqlConnection.Close();
  26. }//phpfensi.com

相关广告
  • mysql too many connections mysql too many connections mysql too many connections
相关阅读

mysql too many connections

2019/10/10 17:32:48 | 谷歌SEO算法 | 云计算