Search code examples
c#asp.netiisweb-configmax-pool-size

Error: The connection is closed


We wrote a application in C# and it works for several years. Recently we got this error.

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

and

The connection is closed.

I found the error when it occurs.

It occurs when the person click the button for database hit to fetch the data. while the data is processing, User close the browser window and trying to open same site for the next time.
I was researched about this issue. In most solutions they have mentioned to close the connection. But we have closed the connection in transaction end.

How to Close the connection when the user close the browser window or is there any solution to fix this issue.

Web Config

<add name="connectionString" 
     connectionString="Data Source='oracl';pwd='password';uid='Server08';Max Pool Size=200" 
     providerName="System.Data.OracleClient" />

I hope someone have the solution for this issue. Thanks


Solution

  • Try using this. i guess you need to clear the connection pool.

    finally
    {
        oraConn.Dispose();
        oraConn.Close();
        OracleConnection.ClearPool(oraConn);
    }