Exemplo n.º 1
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));
            }
        }
        internal void ValidateBeginTransaction()
        {
            if (State != ConnectionState.Open)
            {
                throw new InvalidOperationException(String.Format("{0} requires an open and available Connection. The connection's current state is {1}.", new object[] { "BeginTransaction", State }));
            }

            if (!JdbcConnection.getAutoCommit())
            {
                throw new System.InvalidOperationException("Parallel transactions are not supported.");
            }
        }