I have a production API that connect to a cobol database through ODBC. The ODBC driver sometime pop a too many connections error. I don't think I can do much more to close the connection.
Stopwatch stopwatch = Stopwatch.StartNew();
OdbcConnection con = new OdbcConnection(System.Configuration.ConfigurationManager.ConnectionStrings["LCM"].ConnectionString);
try
{
using (con)
{
con.Open();
var result = GetProductsFromDB(searchEntities, con, clientID);
con.Close();
OdbcConnection.ReleaseObjectPool();
con.Dispose();
stopwatch.Stop();
result.Total = Convert.ToInt32( stopwatch.Elapsed.TotalMilliseconds);
return result.Data;
}
}
catch (Exception ex)
{
OnActionReport(new ReportActionArgs(ex.Message));
throw;
}
finally
{
if (con.State != System.Data.ConnectionState.Closed)
{
con.Close();
OdbcConnection.ReleaseObjectPool();
con.Dispose();
OnActionReport(new ReportActionArgs("Connection Closed finally"));
}
}
When I restart the IIS service the issue clear up and everything work as it should. Does someone have faced this issue with an ODBC driver before?
I finally made a custom connection pool that will chose an available open connection. it's been almost two weeks now without an issue.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.