public override void Open()
        {
            if (_connectionString == null || _connectionString.Length == 0)
            {
                throw ExceptionHelper.ConnectionStringNotInitialized();
            }

            IsConnecting = true;
            try
            {
                if (JdbcConnection != null && !JdbcConnection.isClosed())
                {
                    throw ExceptionHelper.ConnectionAlreadyOpen(_internalState);
                }

                JdbcConnection = ConnectionProvider.GetConnection(ConnectionStringBuilder);

                IsOpened = true;

                OnStateChange(new StateChangeEventArgs(ConnectionState.Closed, ConnectionState.Open));
            }
            catch (SQLWarning warning)
            {
                OnSqlWarning(warning);
            }
            catch (SQLException exp)
            {
                OnSqlException(exp);
            }
            finally
            {
                IsConnecting = false;
            }
        }
Exemplo n.º 2
0
        public override void Close()
        {
            ConnectionState orig = State;

            try {
                ClearReferences();
                if (JdbcConnection != null && !JdbcConnection.isClosed())
                {
                    if (!JdbcConnection.getAutoCommit())
                    {
                        JdbcConnection.rollback();
                    }
                    JdbcConnection.close();
                }
            }
            catch (Exception e) {
                // suppress exception
#if DEBUG
                Console.WriteLine("Exception catched at Conection.Close() : {0}\n{1}\n{2}", e.GetType().FullName, e.Message, e.StackTrace);
#endif
            }
            finally {
                JdbcConnection = null;
                lock (_internalStateSync) {
                    _internalState = ConnectionState.Closed;
                }
            }

            ConnectionState current = State;
            if (current != orig)
            {
                OnStateChange(new StateChangeEventArgs(orig, current));
            }
        }
Exemplo n.º 3
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         try {
             if (JdbcConnection != null && !JdbcConnection.isClosed())
             {
                 JdbcConnection.close();
             }
             JdbcConnection = null;
         }
         catch (java.sql.SQLException exp) {
             throw CreateException(exp);
         }
     }
     base.Dispose(disposing);
 }