简体   繁体   English

C#SQL最大池大小已达到

[英]c# SQL max pool size was reached

I have a simple while loop that checks the database for inserts. 我有一个简单的while循环,用于检查数据库是否有插入。 If its in the loop too long my try catch gets "max pool size was reached" error. 如果它在循环中的时间过长,我的尝试捕获将出现“已达到最大池大小”错误。 So at the bottom of loop I have a connection clearallpools() ; 所以在循环的底部,我有一个连接clearallpools() ; But that still doesn't solve it. 但这仍然无法解决。

while (!quit)
{
connection to database strings timeout=400

read from database


connection.clearallpools();
}

Probably you are not closing your connections...you may want to use 可能您没有关闭连接...您可能想使用

while(!quit){
    //do something here
    using(var connection = GetMyConnection()){
        //do your db reads here
    }
    //do validations and something more here
}

This would ensure your connections are disposed / closed properly. 这样可以确保正确处理/关闭连接。

Also, you do not need to clear your pools. 另外,您无需清除池。

SQLConnection / DBConnection objects implements IDisposable. SQLConnection / DBConnection对象实现IDisposable。 You may want to go thru these 您可能想通过这些

You most probably keep opening new connections in the loop . 您很可能会继续在循环中打开新连接

Above the loop open the connection is a using statement and then use it in the loop. 在循环上方,连接是一个using语句,然后在循环中使用它。 Also note the removal of the clearallpools : 另请注意清除 clearallpools

using(create new connection)
{
    while (!quit)
    {
    connection to database strings timeout=400

    read from database


    // connection.clearallpools(); REMOVE THIS!!!!
    }
}

You're exhausting the connection pool. 您正在耗尽连接池。 Following each read you should close the connection which will release it back to the pool. 每次读取后,您应该关闭连接,这会将其释放回池中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM