示例#1
0
        protected internal SqlTransactionScopeGlobal(SqlConnectionStringBuilder shardMapManagerConnectionString)
        {
            Debug.Assert(SqlTransactionScopeGlobal.current == null);

            SqlConnection conn = new SqlConnection(shardMapManagerConnectionString.ConnectionString);

            conn.Open();

            SqlTransaction tran = conn.BeginTransaction(IsolationLevel.Serializable);

            this.conn = conn;
            this.tran = tran;
            SqlTransactionScopeGlobal.current = this;
        }
示例#2
0
        /// <summary>
        /// Completes the currently active transaction.
        /// </summary>
        internal void FinishTransaction()
        {
            Debug.Assert(this.conn != null);
            Debug.Assert(this.tran != null);
            try
            {
#if DEBUG
                // Raise event and check if current transaction should be aborted.
                //
                SqlStoreEventArgs eventArgs = new SqlStoreEventArgs();

                OnDisposeEvent(eventArgs);

                if (eventArgs.action == SqlStoreEventArgs.SqlStoreTxnFinishAction.TxnAbort)
                {
                    throw new StoreException(
                        Errors.SqlTransactionScopeGlobal_SqlException,
                        this.Success ? "Commit" : "Rollback");
                }
                else
#endif // DEBUG
                {
                    if (this.Success)
                    {
                        this.tran.Commit();
                    }
                    else
                    {
                        this.tran.Rollback();
                    }
                }
            }
            catch (SqlException se)
            {
                throw new StoreException(
                    Errors.SqlTransactionScopeGlobal_SqlException,
                    se,
                    this.Success ? "Commit" : "Rollback");
            }
            finally
            {
                this.tran.Dispose();
                this.conn.Dispose();
                SqlTransactionScopeGlobal.current = null;
            }
        }
示例#3
0
        public virtual IStoreTransactionScope GetTransactionScopeGlobal()
        {
            try
            {
                SqlTransactionScopeGlobal txnScopeGlobal = new SqlTransactionScopeGlobal(this.credentials.ConnectionStringShardMapManager);
                
#if DEBUG
                EventHandler<SqlStoreEventArgs> handler = this.SqlStoreEventGlobal;
                if (handler != null)
                {
                    // If there are any subscribers for SqlStoreEventGlobal event, then register a subscriber function with SqlTransactionScopeGlobal
                    //
                    txnScopeGlobal.TxnScopeGlobalDisposeEvent += TxnScopeGlobalEventHandler;
                }
#endif // DEBUG

                return txnScopeGlobal;
            }
            catch (SqlException se)
            {
                throw new StoreException(
                    Errors.SqlStore_GetTransactionScopeGlobal_SqlException,
                    se);
            }
        }