在c#代码中使用线程时达到的最大池大小

时间:2015-03-27 11:03:09

标签: c# .net ado.net

我有一个控制台应用程序,我想使用线程。在线程中,我打开连接,在某个时间点,它打破了错误

  

从池中获取连接之前经过的超时时间

这是我的连接字符串

  

connectionString =" Data Source = INBLRWIT058068 \ SQL2008R2; Initial Catalog = OMApp; Integrated Security = SSPI; Pooling = True; Min Pool Size = 500; Max Pool Size = 2000"的providerName =" System.Data.SqlClient的"

这是C#代码

static void Main(string[] args)
{
    WithThread();
}

private static void WithThread()
{
    for (int i = 1; i <= 1500; i++)
    {
        Thread thread1 = new Thread(new ThreadStart(GetOrders)); 
        thread1.Start();
    }
}


public static void GetOrders()
{
    using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
    {
        using (SqlCommand command = new SqlCommand("dbo.GetOrders", connection))
        {
            command.CommandTimeout = 2;
            command.CommandType = CommandType.StoredProcedure;

            connection.Open();

            using (var reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    Console.WriteLine(String.Format("{0}, {1}", reader[0], reader[1]));
                }
            }
        }
    }
}

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

尝试使用1500增加最大池大小。