我有一个控制台应用程序,我想使用线程 . 在线程中,我打开连接,在某些时候,它打破了错误
从池中获取连接之前经过的超时时间 .
这是我的连接字符串
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 回答
尝试使用
1500
增加最大池大小 .