OracleTransaction 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示将在数据库中进行的事务。
public ref class OracleTransaction sealed : MarshalByRefObject, IDisposable, System::Data::IDbTransaction
public ref class OracleTransaction sealed : System::Data::Common::DbTransaction
public sealed class OracleTransaction : MarshalByRefObject, IDisposable, System.Data.IDbTransaction
public sealed class OracleTransaction : System.Data.Common.DbTransaction
type OracleTransaction = class
inherit MarshalByRefObject
interface IDbTransaction
interface IDisposable
type OracleTransaction = class
inherit DbTransaction
Public NotInheritable Class OracleTransaction
Inherits MarshalByRefObject
Implements IDbTransaction, IDisposable
Public NotInheritable Class OracleTransaction
Inherits DbTransaction
- 继承
- 继承
- 实现
示例
以下示例创建 OracleConnection 和 OracleTransaction。 它还演示如何使用 BeginTransaction、 Commit和 Rollback 方法。
public void RunOracleTransaction(string connectionString)
{
using (OracleConnection connection = new OracleConnection(connectionString))
{
connection.Open();
OracleCommand command = connection.CreateCommand();
OracleTransaction transaction;
// Start a local transaction
transaction = connection.BeginTransaction(IsolationLevel.ReadCommitted);
// Assign transaction object for a pending local transaction
command.Transaction = transaction;
try
{
command.CommandText =
"INSERT INTO Dept (DeptNo, Dname, Loc) values (50, 'TECHNOLOGY', 'DENVER')";
command.ExecuteNonQuery();
command.CommandText =
"INSERT INTO Dept (DeptNo, Dname, Loc) values (60, 'ENGINEERING', 'KANSAS CITY')";
command.ExecuteNonQuery();
transaction.Commit();
Console.WriteLine("Both records are written to database.");
}
catch (Exception e)
{
transaction.Rollback();
Console.WriteLine(e.ToString());
Console.WriteLine("Neither record was written to database.");
}
}
}
Public Sub RunOracleTransaction(ByVal connectionString As String)
Using connection As New OracleConnection(connectionString)
connection.Open()
Dim command As OracleCommand = connection.CreateCommand()
Dim transaction As OracleTransaction
' Start a local transaction
transaction = connection.BeginTransaction(IsolationLevel.ReadCommitted)
' Assign transaction object for a pending local transaction
command.Transaction = transaction
Try
command.CommandText = _
"INSERT INTO Dept (DeptNo, Dname, Loc) values (50, 'TECHNOLOGY', 'DENVER')"
command.ExecuteNonQuery()
command.CommandText = _
"INSERT INTO Dept (DeptNo, Dname, Loc) values (60, 'ENGINEERING', 'KANSAS CITY')"
command.ExecuteNonQuery()
transaction.Commit()
Console.WriteLine("Both records are written to database.")
Catch e As Exception
transaction.Rollback()
Console.WriteLine(e.ToString())
Console.WriteLine("Neither record was written to database.")
End Try
End Using
End Sub
注解
应用程序通过调用 BeginTransactionOracleConnection 对象来创建 OracleTransaction 对象。 与事务 (关联的所有后续操作(例如,提交或中止事务) )都对 OracleTransaction 对象执行。
属性
Connection |
指定与该事务关联的 OracleConnection 对象。 |
DbConnection |
在派生类中重写时,获取与事务关联的 DbConnection 对象。 (继承自 DbTransaction) |
IsolationLevel |
为该事务指定 IsolationLevel。 |
SupportsSavepoints |
获取一个值,该值指示此 DbTransaction 实例是否支持数据库保存点。
如果为 |
方法
显式接口实现
IDbTransaction.Connection |
获取与事务关联的 DbConnection 对象,或空引用(如果该事务不再有效)。 (继承自 DbTransaction) |