六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 52|回复: 0

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

[复制链接]

升级  20%

2

主题

2

主题

2

主题

童生

Rank: 1

积分
10
 楼主| 发表于 2013-2-4 19:55:54 | 显示全部楼层 |阅读模式
public void testLink()
        {
            int count = 0;
            int intLength = 100;
            MySqlConnection[] conn = new MySqlConnection[intLength];
            MySqlCommand[] stmt = new MySqlCommand[intLength];
            MySqlDataReader[] myReader = new MySqlDataReader[intLength];
            try
            {
                string myConnectionString = "Server=192.160.10.130;UserId=root;Password=root;Database=camera";
                for (count = 0; count < intLength; count++)
                {
                    conn[count] = new MySqlConnection(myConnectionString);
                    string myInsertQuery = "Select * from t_pathinfo";
                    stmt[count] = new MySqlCommand(myInsertQuery);
                    stmt[count].Connection = conn[count];
                    conn[count].Open();
                   
                    myReader[count] = stmt[count].ExecuteReader();
                    if (myReader[count].Read())
                    {
                        string strValue = myReader[count]["pathid"].ToString();
                    }
                    Console.WriteLine(count);
                }
            }
            catch (Exception ex1)
            {
                throw new Exception(ex1.Message);
            }
            finally
            {
                try
                {
                    count --;
                    for (; count >= 0; count--)
                    {
                        myReader[count].Close();
                        conn[count].Close();
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }
        }
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表