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