Business is the real world of some events, such as banking, flight booking, money remittance and so on.
A transaction is a set of operations that are performed as a unit. It either succeeds at execution or fails all.
A transaction has four properties, often called acid. Atomicity (atomicity), consistency (consistency), isolation (isolation), persistence (durability).
1. Atomicity: All operations in the entire transaction, either complete or complete, are not likely to stall in the middle of a link. When an error occurs during execution, the transaction is rolled back (Rollback) to the state before the transaction begins, as if the transaction had never been executed.
2. Consistency: The integrity constraints of the database are not compromised until the transaction begins and after the transaction has ended.
3. Isolation: The isolated state performs transactions so that they appear to be the only operations that the system performs within a given time. If there are two transactions that run at the same time and perform the same function, the isolation of the transaction will ensure that every transaction in the system considers only that the transaction is in use by the system. This attribute is sometimes called serialization, and in order to prevent confusion between transactional operations, the request must be serialized or sequenced so that only one request is used for the same data at a time.
4. Persistence: After the transaction is completed, changes made to the database by the firm persist in the database and are not rolled back.
Ado. NET in simple transaction processing:
using(SqlConnection conn =NewSqlConnection (getconnection ())) {Conn. Open (); //Start a transaction using(SqlTransaction transaction =Conn. BeginTransaction ()) {using(SqlCommand cmd =Conn. CreateCommand ()) {Try{cmd. Transaction= Transaction;//to specify a transaction for a commandCmd.commandtext="INSERT into Tb_user (userid,username) VALUE (' Id0002 ', ' Name0002 ');"; Cmd. ExecuteNonQuery (); Cmd.commandtext="INSERT into Tb_user (userid,username) VALUE (' Id0008 ', ' Name0008 ');"; Cmd. ExecuteNonQuery (); Transaction.commit (); //Transaction CommitResponse.Write ("<script>alert (' successfully written record ');</script>"); } Catch(Exception ex) {transaction. Rollback (); //Transaction RollbackResponse.Write (ex. Message); Response.Write ("<script>alert (' Write record failed ');</script>"); } } } }
The fifth section understands things