Using transaction protection data in ADO.NET (3)

zhaozj2021-02-16  35

Transaction in ADO.NET

ADO.NET supports two transaction models, this is. The NET Framework document is defined as a guide. The Transaction Guide manual describes the database transactions that usually you should know, which affects operating a single target database. A class can provide a transaction guide by using transaction classes and methods by using the transaction border described by ADO.NET. In the next chapter, I will focus on the transaction guide. Automatic transactions are also possible, in order to use class to participate in transactions to coordinate changes across multiple data sources. In this scenario, the transaction itself is treated outside, such as through COM and DTC. You need to know more automatic transactions, you can refer to related automated transactions. Note: When you do not specify a transaction behavior in your code, you should pay attention to the default behavior of the database transaction. For example, SQL Server defaults automatic mode, each transaction-SQL statement or success or failure. To understand which default behavior is the hope that you can get a data source you work, you can help you decide whether you display a definition transaction, or you can understand your system behavior more helpful. Transaction-related classes ADO.NET data provides transaction functions through Connection, Command, and Transaction Class. A typical transaction process is similar to:

1. Open the transaction through connection.begintransaction ()

2. Add statements or stored procedures to transactions by setting up Command.TransAction properties of Command.

3. Relying on the provider, select Transaction.Save () or Transaction.Begin () to create a SavePoint or embedded transaction to enable local rollback.

4. Submission or rollback transaction by using transaction.commit () or transaction.rollback ()

All data providers provide the same basic structure to handle transactions, start connecting transactions, join instructions, using transaction objects to submit or roll back.

SQL Server transaction

SQL Server Data Provide Objects Provide Basic Features of Transactions See the following classes and members:

Class

MEMBER

FUNCTION

SqlConnection

BeGintransaction

Open a new transaction.

SQLCommand

TRANSACTION

Enlist the command associated with the object in an open transaction.

SQLTransaction

Save

Create a savepoint to enable a partial rollback.

SQLTransaction

Rollback

Roll Back a Transaction.

SQLTransaction

Commit

Commitive

SQL Server Data Provider (for SQL Server, the OLE DB Provider is also provided in the way to create embedded transactions in the code, so embedded transactions are not truly supported in SQL Server. So there is only one way to start a transaction in SqlClient - using sqlconnection.begintransaction (). You can't open another transaction in a unified connection until the previous transaction is submitted or rolled, so each connection at any time There is only one open transaction. In order to use local rollback, use sqltransaction.save (). OLE DB transaction OLE DB data provider provides basic functional conditions for transactions See the following classes and members: Class

MEMBER

FUNCTION

OLEDBCONNECTION

BeGintransaction

Open a new transaction.

OLEDBCommand

TRANSACTION

Enlist the command associated with the object in an open transaction.

OLEDBTRANSACTION

Begin

Create a nested transaction, to enable a partial rollback.

OLEDBTRANSACTION

Rollback

Roll Back a Transaction.

OLEDBTRANSACTION

Commit

Commitive

The OLE DB data provider does not provide any way to set SavePoints, and there is a begin () method on the OLEDBTRANSACTION object. This allows you to create an inline transaction (according to your database) to provide similar features. In this case you can have multiple transactions in a single connection. But you must remember that the displayed call submission and rollback. Remember, .NET OLE DB data provider's embedded transaction relies on your database and the specified OLE DB provider. In order to successfully implement embedded matters, it must be supported by your database and OLE DB providers. Oracle Transaction Oracle Data Provider provides basic functional conditions for transactions See the following classes and members:

Class

MEMBER

FUNCTION

OracleConnection

BeGintransaction

Open a new transaction.

OracleCommand

TRANSACTION

Enlist the command associated with the object in an open transaction.

OracleTransaction

Rollback

Roll Back a Transaction.

OracleTransaction

Commit

Commitive

Oracle data providers do not allow you to specify SavePoints or embedded transactions. SavePoints are supported by Oracle, but you can't implement them for the current Oracle data provider version. It is not possible to roll or submit it in Oracle or submit.

转载请注明原文地址:https://www.9cbs.com/read-26486.html

New Post(0)