萬盛學電腦網

 萬盛學電腦網 >> 數據庫 >> mysql教程 >> mysql too many connections

mysql too many connections

mysql教程 too many connections

解決辦法:

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

2.檢查MySqlConnection使用後是否有做close()

3.不要把MysqlConnection連接弄成 static 的,每次連接都創建一個新的連接

eg:

復制內容到剪貼板 程序代碼

  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();

            }

copyright © 萬盛學電腦網 all rights reserved