已达到c#SQL最大池大小
我有一个简单的while循环来检查数据库中的插入。如果循环中的时间太长,我的try-catch会出现“已达到最大池大小”错误。所以在循环的底部有一个连接已达到c#SQL最大池大小,c#,sql,connection-pooling,C#,Sql,Connection Pooling,我有一个简单的while循环来检查数据库中的插入。如果循环中的时间太长,我的try-catch会出现“已达到最大池大小”错误。所以在循环的底部有一个连接clearallpools();但这仍然不能解决问题 while (!quit) { connection to database strings timeout=400 read from database connection.clearallpools(); } 您很可能一直在循环中打开新连接 在循环打开上方,连接是一个using语
clearallpools()
;但这仍然不能解决问题
while (!quit)
{
connection to database strings timeout=400
read from database
connection.clearallpools();
}
您很可能一直在循环中打开新连接 在循环打开上方,连接是一个
using
语句,然后在循环中使用它。还要注意删除ClearAllPool
:
using(create new connection)
{
while (!quit)
{
connection to database strings timeout=400
read from database
// connection.clearallpools(); REMOVE THIS!!!!
}
}
可能您没有关闭连接…您可能想使用
while(!quit){
//do something here
using(var connection = GetMyConnection()){
//do your db reads here
}
//do validations and something more here
}
这将确保正确处理/关闭您的连接
此外,您不需要清除池
SQLConnection/DBConnection对象实现IDisposable。你可能想看看这些
- 您正在耗尽连接池。每次读取后,您应该关闭连接,然后将其释放回池。将您的语句分成多个批。达到最大池大小是一件非常糟糕的事情。