/// <summary> /// Closes the Connection to the Database /// </summary> /// <param name="forceClose">Indicates that the connection should be closed even if keepOpen was specified when the Connection was opened</param> /// <param name="rollbackTrans">Indicates that the Transaction should be rolled back because something has gone wrong</param> public void Close(bool forceClose, bool rollbackTrans) { //Don't close if we're keeping open and not forcing Close or rolling back a Transaction if (this._keepOpen && !forceClose && !rollbackTrans) { return; } switch (this._db.State) { case ConnectionState.Open: //Finish the Transaction if exists if (this._dbtrans != null) { if (!rollbackTrans) { //Commit normally this._dbtrans.Commit(); } else { //Want to Rollback this._dbtrans.Rollback(); } this._dbtrans = null; this._db.Close(); } this._keepOpen = false; break; } }
/// <summary> /// Opens a Connection to the Database /// </summary> /// <param name="keepOpen">Indicates that the Connection should be kept open and a Transaction started</param> /// <param name="level">Isolation Level to use</param> public void Open(bool keepOpen, IsolationLevel level) { switch (this._db.State) { case ConnectionState.Broken: case ConnectionState.Closed: this._db.Open(); //Start a Transaction if (this._dbtrans == null) { this._dbtrans = this._db.BeginTransaction(level); } break; } if (keepOpen) this._keepOpen = true; }