none
Connection.Close RRS feed

  • Question

  • public class DataAccessor
          {
             private OracleConnection m_connection;   // Connection to the NACS database
    
             /// <summary>
             /// Constructor
             /// </summary>
             public DataAccessor()
             {
                // Get the Oracle DB connection string from the app.config
                string encryptedString = System.Configuration.ConfigurationManager.AppSettings["OracleDBConnectionString"];
    
                if (encryptedString == null || encryptedString.Length == 0)
                {
                   throw new Exception("No 'OracleDBConnectionString' found in app.config");
                }
    
                Encryptor encryptor = new Encryptor();
                string connectionString = encryptor.UndoIt(encryptedString);
    
                // Create and open connection to database
                m_connection = new OracleConnection(connectionString);
                m_connection.Open();
             }
    
             /// <summary>
             /// Destructor
             /// </summary>
             ~DataAccessor()
             {
                // Close connection to NACS database
                if (m_connection != null && m_connection.State != ConnectionState.Closed)
                {
                   m_connection.Close();
                }
             }
    The MSDN docs I read suggested that you need to call the close method when done with a connection. However, I get "GeneralException" with no error message when I try to close my connection object. What to do?

    Wednesday, February 3, 2010 9:13 PM

Answers

All replies