mysql too many connections
2019/10/10/17:32:48 阅读:1788 来源:谷歌SEO算法 标签:
云计算
mysql too many connections
解决办法:
1.在使用MYSQL数据源的地方加入try/catch/finally
2.检查MySqlConnection使用后是否有做close()
3.不要把MysqlConnection连接弄成 static 的,每次连接都创建一个新的连接.
程序代码如下:
- MySql.Data.MySqlClient.MySqlConnectionmysqlConnection=newMySqlConnection(SDS.SMS.DAL.SqlHelper.strSMS);
- mysqlConnection.Open();
- stringselectCommand="selectid,model,number,brand,sendtime,pubdate,autoinsert_flag,mobilephonefromtbl_saledatawhereautoinsert_flag=0andsendtime='"+date+"'";
- try
- {
- IListIlst=newList();
- using(MySqlDataReaderdr=MySql.Data.MySqlClient.MySqlHelper.ExecuteReader(SDS.SMS.DAL.SqlHelper.strSMS,selectCommand))
- {
- while(dr.Read())
- {
- Ilst.Add(Populater(dr));
- }
- returnIlst;
- //关闭
- dr.Close();
- mysqlConnection.Close();
- }
- }
- catch(Exceptione)
- {
- throwe;
- }
- finally
- {
- mysqlConnection.Close();
- }//phpfensi.com
热门评论