我有一个简单的while循环来检查数据库的插入。如果它的循环太长,我的try catch会得到“最大池大小已达到”错误。所以在循环的底部我有一个连接clearallpools()
;但是这仍然不能解决问题。c#达到SQL最大池大小
while (!quit)
{
connection to database strings timeout=400
read from database
connection.clearallpools();
}
我有一个简单的while循环来检查数据库的插入。如果它的循环太长,我的try catch会得到“最大池大小已达到”错误。所以在循环的底部我有一个连接clearallpools()
;但是这仍然不能解决问题。c#达到SQL最大池大小
while (!quit)
{
connection to database strings timeout=400
read from database
connection.clearallpools();
}
你最有可能保持在循环打开新的连接。
上面的循环打开连接是一个using
声明,然后在循环中使用它。另外还要注意clearallpools
的去除:
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。你可能想去这些直通
你用尽了连接池。在每次读取之后,您应关闭连接,将其释放回池中。
把你的陈述分成几个批次。达到最大池大小是一件非常糟糕的事情。 – 2011-05-10 20:31:20