sharpds77 发表于 2016-10-24 06:15:17

用C#来测试Mysql数据库的最大连接数

  public void testLink()
        {
            int count = 0;
            int intLength = 100;
            MySqlConnection[] conn = new MySqlConnection;
            MySqlCommand[] stmt = new MySqlCommand;
            MySqlDataReader[] myReader = new MySqlDataReader;
            try
            {
                string myConnectionString = "Server=192.160.10.130;UserId=root;Password=root;Database=camera";
                for (count = 0; count < intLength; count++)
                {
                    conn = new MySqlConnection(myConnectionString);
                    string myInsertQuery = "Select * from t_pathinfo";
  stmt = new MySqlCommand(myInsertQuery);
                    stmt.Connection = conn;
                    conn.Open();
                   
                    myReader = stmt.ExecuteReader();
                    if (myReader.Read())
                    {
                        string strValue = myReader["pathid"].ToString();
                    }
                    Console.WriteLine(count);
                }
            }
            catch (Exception ex1)
            {
                throw new Exception(ex1.Message);
            }
            finally
            {
                try
                {
                    count --;
                    for (; count >= 0; count--)
                    {
                        myReader.Close();
                        conn.Close();
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }
        }
页: [1]
查看完整版本: 用C#来测试Mysql数据库的最大连接数