今天我发现一个问题,我的程序在进行 SQL 查询时冻结,并且我得到一个异常“超时已过期,在从池中获取连接之前经过的超时时间”
我的C#
请求代码:
public int LoadParameter(string parameter,string table,string condition,string find)
{
int index = 0;
SqlConnection dbConnection = new SqlConnection
{
ConnectionString = ConfigurationManager.ConnectionStrings["Connection"].ToString()
};
try
{
dbConnection.Open();
SqlCommand command = new SqlCommand
{
CommandText = string.Format(@"Select {0} FROM {1} WHERE {2} = '{3}'", parameter, table, condition, find),
Connection = dbConnection
};
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
index = reader.GetInt32(0);
}
dbConnection.Close();
SqlConnection.ClearPool(dbConnection);
return index;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return 0;
}
finally
{
dbConnection.Close();
SqlConnection.ClearPool(dbConnection);
}
}
我关闭了连接,但没有帮助。