繁体   English   中英

C#SQL最大池大小已达到

[英]c# SQL max pool size was reached

我有一个简单的while循环,用于检查数据库是否有插入。 如果它在循环中的时间过长,我的尝试捕获将出现“已达到最大池大小”错误。 所以在循环的底部,我有一个连接clearallpools() ; 但这仍然无法解决。

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

read from database


connection.clearallpools();
}

可能您没有关闭连接...您可能想使用

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

这样可以确保正确处理/关闭连接。

另外,您无需清除池。

SQLConnection / DBConnection对象实现IDisposable。 您可能想通过这些

您很可能会继续在循环中打开新连接

在循环上方,连接是一个using语句,然后在循环中使用它。 另请注意清除 clearallpools

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

    read from database


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

您正在耗尽连接池。 每次读取后,您应该关闭连接,这会将其释放回池中。

暂无
暂无

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

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