MySQL Too many connections

Source: Internet
Author: User
Tags mysql tutorial

MySQL Tutorial too many connections

Solution:

1. Join try/catch/finally where you use MySQL data source

2. Check whether the mysqlconnection after use to do close ()

3. Do not make the mysqlconnection connection static, each connection creates a new connection

eg

Copy content to Clipboard program code

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;

Shut down
Dr. Close ();

Mysqlconnection.close ();

}
}
catch (Exception e)
{
Throw e;
}
Finally
{
Mysqlconnection.close ();

           }

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.