当我尝试从生产复制本地数据库获取所有用户名密码时,我收到此错误,我想这是因为没有正确关闭连接,但我不知道如何。我正在使用Microsoft企业库,蚂蚁思考或评论它?
Timeout expired. The timeout period elapsed prior to
obtaining a connection from the pool. This may have occurred
because all pooled connections were in use and max pool size was reached.
这是获取用户名和密码并产生错误的方法。
private Model.UsernameandPass GetUsernamePass(string AccountNumber)
{
Model.UsernameandPass model = null;
string myConnection = System.Configuration.ConfigurationManager.ConnectionStrings[connectionName].ToString();
SqlDatabase db = new SqlDatabase(myConnection);
using (DbCommand command = db.GetStoredProcCommand("Get_TheUsernamePassWordFromProduction"))
{
db.AddInParameter(command, "AccountNumber", DbType.String, AccountNumber);
var result = db.ExecuteReader(command);
try
{
while (result.Read())
{
model = new Model.UsernameandPass();
model.Username = result.GetString(1);
model.Password = result.GetString(2);
}
}
catch (Exception ex)
{
}
}
db = null;
return model;
}
程序运行一段时间后,我收到此行中的错误。
var result = db.ExecuteReader(command);
答案 0 :(得分:0)
您收到该错误是因为无法建立连接,而仅,因为它们未正确关闭。检查您尝试使用数据库进行身份验证的用户的权限。如果您以编程方式打开/关闭连接,请务必致电.open()
/ .close()
。
Check this link。您可能希望增加池大小,或检查长时间运行的查询。