超时时间已到。在从池中获取连接之前超时时间已过。出现这种情况可能是因为所有池连接都已被使用并已达到最大池大小。
运行程序时出现这个问题,可是我每次用完连接后都关闭了连接.为什么还会出现这个问题?
我调用的代码:
strInsert="insert ......";
link.UpdateDataBase(strInsert);其中 UpdateDataBase函数定义为:
public int UpdateDataBase(string tempStrSQL)
{
this.myConnection = new SqlConnection(connectionString);
//使用Command之前一定要先打开连接,后关闭连接,而DataAdapter则会自动打开关闭连接SqlCommand tempSqlCommand = new SqlCommand(tempStrSQL,this.myConnection);
if(myConnection.State==ConnectionState.Closed)
{
myConnection.Open();
}
int intNumber = tempSqlCommand.ExecuteNonQuery();//返回数据库中影响的行数
if(myConnection.State==ConnectionState.Open)
{
myConnection.Close();
}
return intNumber;
}请大家帮帮忙谢谢