mysql too many connections
解决办法:
1.在使用MYSQL数据源的地方加入try/catch/finally
2.检查MySqlConnection使用后是否有做close()
3.不要把MysqlConnection连接弄成 static 的,每次连接都创建一个新的连接.
程序代码如下:
- MySql.Data.MySqlClient.MySqlConnection mysqlConnection = new MySqlConnection(SDS.SMS.DAL.SqlHelper.strSMS);
- mysqlConnection.Open();
- string selectCommand = "select id,model,number,brand,sendtime,pubdate,autoinsert_flag,mobilephone from tbl_saledata where autoinsert_flag=0 and sendtime='" + date + "'";
- try
- {
- IList Ilst = new List();
- using (MySqlDataReader dr = MySql.Data.MySqlClient.MySqlHelper.ExecuteReader(SDS.SMS.DAL.SqlHelper.strSMS, selectCommand))
- {
- while (dr.Read())
- {
- Ilst.Add(Populater(dr));
- }
- return Ilst;
- //关闭
- dr.Close();
- mysqlConnection.Close();
- }
- }
- catch (Exception e)
- {
- throw e;
- }
- finally
- {
- mysqlConnection.Close();
- } //Vevb.com
新闻热点
疑难解答