/// <include file='doc\SqlTransaction.uex' path='docs/doc[@for="SqlTransaction.Save"]/*' /> public void Save(string savePointName) { SqlConnection.SqlClientPermission.Demand(); // MDAC 81476 // If this transaction has been completed, throw exception since it is unusable. if (_sqlConnection == null) { throw ADP.TransactionZombied(this); } // ROLLBACK takes either a save point name or a transaction name. It will rollback the // transaction to either the save point with the save point name or begin with the // transacttion name. So, to rollback a nested transaction you must have a save point. // SAVE TRANSACTION MUST HAVE AN ARGUMENT!!! Save Transaction without an arg throws an // exception from the server. So, an overload for SaveTransaction without an arg doesn't make // sense to have. Save Transaction does not affect the transaction level. if (ADP.IsEmpty(savePointName)) { throw SQL.NullEmptyTransactionName(); } try { savePointName = SqlConnection.FixupDatabaseTransactionName(savePointName); _sqlConnection.ExecuteTransaction(TdsEnums.TRANS_SAVE + " " + savePointName, ADP.SaveTransaction); } catch { // if not zombied (connection still open) and not in transaction, zombie if (null != _sqlConnection && GetServerTransactionLevel() == 0) { Zombie(); } throw; } }
// // OTHER PUBLIC METHODS // public void ChangeDatabase(string database) { if (_parser.PendingData) { throw ADP.OpenConnectionRequired(ADP.ChangeDatabase, Connection.State); } // MDAC 73598 - add brackets around database database = SqlConnection.FixupDatabaseTransactionName(database); _parser.TdsExecuteSQLBatch("use " + database, _connectionOptions.ConnectTimeout); _parser.Run(RunBehavior.UntilDone); }
/// <include file='doc\SqlTransaction.uex' path='docs/doc[@for="SqlTransaction.Rollback1"]/*' /> public void Rollback(string transactionName) { SqlConnection.SqlClientPermission.Demand(); // MDAC 81476, 81678, 82093 // If this transaction has been completed, throw exception since it is unusable. if (_sqlConnection == null) { throw ADP.TransactionZombied(this); } // ROLLBACK takes either a save point name or a transaction name. It will rollback the // transaction to either the save point with the save point name or begin with the // transacttion name. NOTE: for simplicity it is possible to give all save point names // the same name, and ROLLBACK will simply rollback to the most recent save point with the // save point name. if (ADP.IsEmpty(transactionName)) { throw SQL.NullEmptyTransactionName(); } try { transactionName = SqlConnection.FixupDatabaseTransactionName(transactionName); _sqlConnection.ExecuteTransaction(TdsEnums.TRANS_ROLLBACK + " " + transactionName, ADP.RollbackTransaction); if (0 == GetServerTransactionLevel()) { // This transaction has been completed. Zombie(); } } catch { // if not zombied (connection still open) and not in transaction, zombie if (null != _sqlConnection && GetServerTransactionLevel() == 0) { Zombie(); } throw; } }
internal void ExecuteTransactionPreYukon(SqlInternalConnection.TransactionRequest transactionRequest, string transactionName, System.Data.IsolationLevel iso, SqlInternalTransaction internalTransaction) { StringBuilder builder = new StringBuilder(); switch (iso) { case System.Data.IsolationLevel.Unspecified: break; case System.Data.IsolationLevel.Chaos: throw SQL.NotSupportedIsolationLevel(iso); case System.Data.IsolationLevel.ReadUncommitted: builder.Append("SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED"); builder.Append(";"); break; case System.Data.IsolationLevel.Serializable: builder.Append("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE"); builder.Append(";"); break; case System.Data.IsolationLevel.Snapshot: throw SQL.SnapshotNotSupported(System.Data.IsolationLevel.Snapshot); case System.Data.IsolationLevel.ReadCommitted: builder.Append("SET TRANSACTION ISOLATION LEVEL READ COMMITTED"); builder.Append(";"); break; case System.Data.IsolationLevel.RepeatableRead: builder.Append("SET TRANSACTION ISOLATION LEVEL REPEATABLE READ"); builder.Append(";"); break; default: throw ADP.InvalidIsolationLevel(iso); } if (!ADP.IsEmpty(transactionName)) { transactionName = " " + SqlConnection.FixupDatabaseTransactionName(transactionName); } switch (transactionRequest) { case SqlInternalConnection.TransactionRequest.Begin: builder.Append("BEGIN TRANSACTION"); builder.Append(transactionName); break; case SqlInternalConnection.TransactionRequest.Commit: builder.Append("COMMIT TRANSACTION"); builder.Append(transactionName); break; case SqlInternalConnection.TransactionRequest.Rollback: builder.Append("ROLLBACK TRANSACTION"); builder.Append(transactionName); break; case SqlInternalConnection.TransactionRequest.IfRollback: builder.Append("IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION"); builder.Append(transactionName); break; case SqlInternalConnection.TransactionRequest.Save: builder.Append("SAVE TRANSACTION"); builder.Append(transactionName); break; } this._parser.TdsExecuteSQLBatch(builder.ToString(), base.ConnectionOptions.ConnectTimeout, null, this._parser._physicalStateObj); this._parser.Run(RunBehavior.UntilDone, null, null, null, this._parser._physicalStateObj); if (transactionRequest == SqlInternalConnection.TransactionRequest.Begin) { this._parser.CurrentTransaction = internalTransaction; } }
protected override void ChangeDatabaseInternal(string database) { database = SqlConnection.FixupDatabaseTransactionName(database); this._parser.TdsExecuteSQLBatch("use " + database, base.ConnectionOptions.ConnectTimeout, null, this._parser._physicalStateObj); this._parser.Run(RunBehavior.UntilDone, null, null, null, this._parser._physicalStateObj); }