DataSet ds = db.FindDataAdapter("select * from news order by rand() LIMIT 6;");
public DataSet FindDataAdapter(string sql,params string[] str)
{
MySqlConnection conn = DB.Getconn();
conn.Open();
MySqlDataAdapter msd = new MySqlDataAdapter(sql,conn);
DataSet ds = new DataSet();
msd.Fill(ds);
msd.Dispose();
CloseConnection(conn);
return ds;
}
private static void CloseConnection(MySqlConnection conn)
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
conn.Dispose();
}
}
执行完后Mysql 查看链接还有sleep 挂起的链接 如何释放?
我处理这种扯蛋事的办法是,
给每个连接记录下其在数据库连接池的ID,通过这个语句,查询得到
SELECT * FROM information_schema.processlist
然后在这个连接断开的时候,再将这个连接重数据表的连接池里删除掉,
kill [connid]
然后就满意了,当然了你要确定你的连接对应的连接ID,如何确定方法很多,我使用的方法是连接前后,查询最大连接ID 变化了,那么一定是新连接的ID