Mysql too connector connections

Source: Internet
Author: User

Mysql tutorial too connector connections

Solution:

1. Add try/catch/finally to the location where the MYSQL data source is used

2. Check whether close () is performed after MySqlConnection is used ()

3. Do not make the MysqlConnection connection static. Each connection creates a new connection.

Eg:

Copy the content to the 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;

// Close
Dr. Close ();

MysqlConnection. Close ();

}
}
Catch (Exception e)
{
Throw e;
}
Finally
{
MysqlConnection. Close ();

}

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.