Author: nicko
Date: Mon Mar 27 04:57:23 2006
New Revision: 389130

URL: http://svn.apache.org/viewcvs?rev=389130&view=rev
Log:
Fix for LOG4NET-73. Added code to cleanup the connection and command objects 
that are stored in members if the InitializeDatabaseConnection method is called 
multiple times.

Modified:
    logging/log4net/trunk/src/Appender/AdoNetAppender.cs

Modified: logging/log4net/trunk/src/Appender/AdoNetAppender.cs
URL: 
http://svn.apache.org/viewcvs/logging/log4net/trunk/src/Appender/AdoNetAppender.cs?rev=389130&r1=389129&r2=389130&view=diff
==============================================================================
--- logging/log4net/trunk/src/Appender/AdoNetAppender.cs (original)
+++ logging/log4net/trunk/src/Appender/AdoNetAppender.cs Mon Mar 27 04:57:23 
2006
@@ -407,14 +407,30 @@
                override protected void OnClose() 
                {
                        base.OnClose();
+
+                       // Close the cached command and connection objects
                        if (m_dbCommand != null)
                        {
-                               m_dbCommand.Dispose();
+                               try
+                               {
+                                       m_dbCommand.Dispose();
+                               }
+                               catch (Exception ex)
+                               {
+                                       LogLog.Warn("AdoNetAppender: Exception 
while disposing cached command object", ex);
+                               }
                                m_dbCommand = null;
                        }
                        if (m_dbConnection != null)
                        {
-                               m_dbConnection.Close();
+                               try
+                               {
+                                       m_dbConnection.Close();
+                               }
+                               catch (Exception ex)
+                               {
+                                       LogLog.Warn("AdoNetAppender: Exception 
while disposing cached connection object", ex);
+                               }
                                m_dbConnection = null;
                        }
                }
@@ -607,6 +623,32 @@
                {
                        try
                        {
+                               // Cleanup any existing command or connection
+                               if (m_dbCommand != null)
+                               {
+                                       try
+                                       {
+                                               m_dbCommand.Dispose();
+                                       }
+                                       catch (Exception ex)
+                                       {
+                                               LogLog.Warn("AdoNetAppender: 
Exception while disposing cached command object", ex);
+                                       }
+                                       m_dbCommand = null;
+                               }
+                               if (m_dbConnection != null)
+                               {
+                                       try
+                                       {
+                                               m_dbConnection.Close();
+                                       }
+                                       catch (Exception ex)
+                                       {
+                                               LogLog.Warn("AdoNetAppender: 
Exception while disposing cached connection object", ex);
+                                       }
+                                       m_dbConnection = null;
+                               }
+
                                // Create the connection object
                                m_dbConnection = 
(IDbConnection)Activator.CreateInstance(ResolveConnectionType());
                        
@@ -665,6 +707,20 @@
                        {
                                try
                                {
+                                       // Cleanup any existing command or 
connection
+                                       if (m_dbCommand != null)
+                                       {
+                                               try
+                                               {
+                                                       m_dbCommand.Dispose();
+                                               }
+                                               catch (Exception ex)
+                                               {
+                                                       
LogLog.Warn("AdoNetAppender: Exception while disposing cached command object", 
ex);
+                                               }
+                                               m_dbCommand = null;
+                                       }
+
                                        // Create the command object
                                        m_dbCommand = 
m_dbConnection.CreateCommand();
                


Reply via email to