public override void Commit (); 例外 Exception 在尝试提交事务时出错。 InvalidOperationException 已提交或回滚事务。 或 连接已断开。 示例 以下示例创建 SqlConnection 和SqlTransaction。 它还演示如何使用 Commit、 BeginTransaction和Rollback 方法。 事务在任何错误时都回滚。 Try / Catch 错误处理用于在尝试...
方法Commit等效于 Transact-SQL COMMIT TRANSACTION 语句。 提交事务后,无法回滚该事务,因为所有修改都已成为数据库的永久部分。 有关详细信息,请参阅COMMIT TRANSACTION (Transact-SQL)。 备注 Try/Catch提交或回滚SqlTransaction时,应始终使用异常处理。 如果连接终止或事务已在服务器上回滚,则和Rollback都会Commit生成...
显式事务是指这样的事务:您在其中通过 API 函数或发出 Transact-SQL BEGIN TRANSACTION、COMMIT TRANSACTION、COMMIT WORK、ROLLBACK TRANSACTION 或ROLLBACK WORK Transact-SQL 语句明确定义事务的开始和结束。 当事务结束时,连接将返回到启动显式事务前所处的事务模式,这可能是隐式模式,或自动提交模式。
ROLLBACK TRANSACTION erases all data modifications made from the start of the transaction or to a savepoint. It also frees resources held by the transaction. ROLLBACK TRANSACTION without a savepoint_name or transaction_name rolls back to the beginning of the transaction. When nesting transactions, ...
You can't roll back a transaction after aCOMMIT TRANSACTIONstatement is issued, because the data modifications were made a permanent part of the database. The Database Engine increments the transaction count within a statement only when the transaction count is 0 at the start of the statement....
外顯交易是透過 API 函數或藉由發出 Transact-SQL BEGIN TRANSACTION、COMMIT TRANSACTION、COMMIT WORK、ROLLBACK TRANSACTION 或ROLLBACK WORK Transact-SQL 陳述式,明確定義交易的啟動與結束的一種交易。 當交易結束時,連線便會回到外顯交易啟動之前的交易模式,可能是隱含或自動認可模式。
ROLLBACK TRANSACTION statements in triggers terminate the batch containing the statement that fired the trigger; subsequent statements in the batch aren't executed.The effect of a ROLLBACK on cursors is defined by these three rules:With CURSOR_CLOSE_ON_COMMIT set ON, ROLLBACK closes, but doesn...
BEGINTRANSACTION;INSERTINTOCustomers(FirstName,LastName,Email)VALUES('John','Doe','john.doe@example.com');SAVETRANSACTIONSavePoint1;UPDATEOrdersSETStatus='Completed'WHERECustomerID=1;IFerror_occurredBEGINROLLBACKTRANSACTIONSavePoint1;END;COMMIT;
仅当事务被引用所有数据的逻辑都正确时,Transact-SQL 程序员才应发出 COMMIT TRANSACTION 命令。 如果所提交的事务是 Transact-SQL 分布式事务,COMMIT TRANSACTION 将触发 MS DTC 使用两阶段提交协议,以便提交所有涉及该事务的服务器。如果本地事务跨越同一数据库引擎实例上的两个或多个数据库,则该实例将使用内部的两...
When ALTER INDEX REORGANIZE uses explicit transactions (for example, ALTER INDEX inside a BEGIN TRAN ... COMMIT/ROLLBACK) instead of the default implicit transaction mode, the locking behavior of REORGANIZE becomes more restrictive, potentially causing blocking. For more information about implicit trans...