![](/img/trans.png)
[英]ASP - the timeout period elapsed prior to obtaining a connection from the pool
[英]The timeout period elapsed prior to obtaining a connection from pool
我的作业代码有问题。 我们必须使用更新的用户来创建一些数据库,但是这些错误和程序崩溃使我出错了。这是完整的错误代码,并且有代码。
错误:MySql.Data.MySqlClient.MySqlException(0x80004005):错误连接:超时已过期。 从池中获取连接之前已经过超时时间。 这可能是因为所有池化连接都在使用中,并且达到了最大池大小。
我尝试使用query.CommandTimeout = 60; 但我认为它没用,您怎么看?
MySqlConnection connect = new
MySqlConnection("Server=localhost;Database=Work;Uid=root;Pwd='1234';");
connect.Open();
MySqlCommand query = new MySqlCommand(@"UPDATE user
SET User_Name=@User_Name,User_BankBalance=@User_BankBalance,
User_Password=@User_Password,LottoTimer=@LottoTimer
WHERE User_Name='" + Escape(u.Username) + "'", connect);
using (query)
{
query.CommandType = System.Data.CommandType.Text;
query.Parameters.AddWithValue("@User_Name", Escape(u.Username));
query.Parameters.AddWithValue("@User_BankBalance", u.BankBalance);
query.Parameters.AddWithValue("@User_Password", u.Password);
query.Parameters.AddWithValue("@LottoTimer", u.LottoTimer);
query.Dispose();
query.Prepare();
query.ExecuteNonQuery();
}
connect.Close();
return;
您的方法应如下所示:
string query =
@"UPDATE user SET"
+ " User_Name=@User_Name,"
+ " User_BankBalance=@User_BankBalance,"
+ " User_Password=@User_Password,"
+ " LottoTimer=@LottoTimer"
+ " WHERE User_Name='" + Escape(u.Username) + "'";
using( var connect = new MySqlConnection("Server=localhost;Database=Work;Uid=root;Pwd='1234';"))
using( var query = new MySqlCommand(query, connect))
{
connect.Open();
query.CommandType = System.Data.CommandType.Text;
query.Parameters.AddWithValue("@User_Name", Escape(u.Username));
query.Parameters.AddWithValue("@User_BankBalance", u.BankBalance);
query.Parameters.AddWithValue("@User_Password", u.Password);
query.Parameters.AddWithValue("@LottoTimer", u.LottoTimer);
query.Prepare();
query.ExecuteNonQuery();
}
return;
放置MySqlConnection很重要,因此它可以再次用于池中。 您遇到的问题是池中使用了所有连接,并且它正在等待连接-直到超时。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.