public void Return(AbstractSqlConnectionDescriptor connDesc, IDbConnection conn)
{
bool closeConn = false;
if (!connDesc.UsePooling())
{
closeConn = true;
}
else
{
lock (_cache)
{
if (_cache.ContainsKey(connDesc))
{
// already have a connection for this connstr. We're tolerant of this, just
// go ahead and close the second connection.
closeConn = true;
}
else
{
_cache[connDesc] = new TimestampedData<IDbConnection>(conn);
}
}
}
if (closeConn)
{
// Not caching it, just close it.
try
{
if (_log.IsDebugEnabled)
{
_log.Debug("Closing DB connection: " + conn.ConnectionString);
}
conn.Close();
}
catch (Exception e)
{
// This exception is not rethrown because we don't want to mask any
// previous exception that might be being thrown out of "invokeMe".
_log.Warn("Caught an exception while trying to close a DB connection we just used.", e);
}
}
}