logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Craig Boland <cnbol...@sbcglobal.net>
Subject Re: ADONetAppender.ActivateOptions() causes Connection Leak?
Date Tue, 21 Mar 2006 12:43:08 GMT
It appears that calling ActivateOptions() successively
will cause a connection leak, since is calls the
InitializeDatabaseConnection() method, which creates
and opens a new connection instance with each call.

I'm not too familiar with the AdoNetAppender. Is there
a way to close it programmatically before calling
ActivateOptions()? If so, that would be a work-around.

It seems to me that a method named
"InitializeDatabaseConnection" would check the current
instance and close it before opening a new one.

Here's what I'd add to the
InitializeDatabaseConnection() method:

private void InitializeDatabaseConnection()
{
  try
  {
    // Close the current instance
    if(m_dbConnection != null)
    {
        m_dbConnection.Dispose();
    }

    // Create the connection object
    m_dbConnection =
(IDbConnection)Activator.CreateInstance(ResolveConnectionType());

    //...


> > Subject: ADONetAppender.ActivateOptions() causes
> Connection Leak?
> Date: Mon, 20 Mar 2006 17:21:21 -0700
> From: "Wanner, Nick" <nwanner@zolldata.com>
> To: <log4net-user@logging.apache.org>
> 
> I am modifying the buffer size and the connection
> string of
> ADONetAppenders programmatically and I am getting a
> SqlConnection leak.
> The number of open connections to SQL Server grows
> to the max connection
> pool size when I do this repeatedly.
>  
> The leak occurs when I call ActivateOptions on the
> ADONetAppender after
> I set its BufferSize and ConnectionString.  The
> documentation says that
> you need to call ActivateOptions after you modify
> the appenders
> configuration.  The ActivateOptions method creates a
> new connection and
> overwrites the ADONetAppenders connect member
> m_dbConnection with the
> new instance.  The leak occurs because the the old
> connection is not
> closed.
>  
> Here is basically what I am doing:
> ...
>
((log4net.Appender.BufferingAppenderSkeleton)logAppender).BufferSize
> =
> size;
>
((log4net.Appender.ADONetAppender)logAppender).ConnectionString
> =
> ADOConnectionString;
>
((log4net.Appender.ADONetAppender)logAppender).ActivateOptions();
>  
> I am doing something wrong or is this a bug?
>  
> thanks,
> Nick
> <mailto:'log4net-user@logging.apache.org'> 
> 


Mime
View raw message