OdbcTransaction クラス
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
データ ソースで実行される SQL トランザクションを表します。 このクラスは継承できません。
public ref class OdbcTransaction sealed : System::Data::Common::DbTransaction
public ref class OdbcTransaction sealed : MarshalByRefObject, IDisposable, System::Data::IDbTransaction
public sealed class OdbcTransaction : System.Data.Common.DbTransaction
public sealed class OdbcTransaction : MarshalByRefObject, IDisposable, System.Data.IDbTransaction
type OdbcTransaction = class
inherit DbTransaction
type OdbcTransaction = class
inherit MarshalByRefObject
interface IDbTransaction
interface IDisposable
Public NotInheritable Class OdbcTransaction
Inherits DbTransaction
Public NotInheritable Class OdbcTransaction
Inherits MarshalByRefObject
Implements IDbTransaction, IDisposable
- 継承
- 継承
- 実装
次の例では、OdbcConnection と OdbcTransactionを作成します。 また、BeginTransaction、Commit、および Rollback メソッドの使用方法についても説明します。
public static void ExecuteTransaction(string connectionString)
{
using (OdbcConnection connection =
new OdbcConnection(connectionString))
{
OdbcCommand command = new OdbcCommand();
OdbcTransaction transaction = null;
// Set the Connection to the new OdbcConnection.
command.Connection = connection;
// Open the connection and execute the transaction.
try
{
connection.Open();
// Start a local transaction
transaction = connection.BeginTransaction();
// Assign transaction object for a pending local transaction.
command.Connection = connection;
command.Transaction = transaction;
// Execute the commands.
command.CommandText =
"Insert into Region (RegionID, RegionDescription) VALUES (100, 'Description')";
command.ExecuteNonQuery();
command.CommandText =
"Insert into Region (RegionID, RegionDescription) VALUES (101, 'Description')";
command.ExecuteNonQuery();
// Commit the transaction.
transaction.Commit();
Console.WriteLine("Both records are written to database.");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
try
{
// Attempt to roll back the transaction.
transaction.Rollback();
}
catch
{
// Do nothing here; transaction is not active.
}
}
// The connection is automatically closed when the
// code exits the using block.
}
}
Public Sub ExecuteTransaction(ByVal connectionString As String)
Using connection As New OdbcConnection(connectionString)
Dim command As New OdbcCommand()
Dim transaction As OdbcTransaction
' Set the Connection to the new OdbcConnection.
command.Connection = connection
' Open the connection and execute the transaction.
Try
connection.Open()
' Start a local transaction.
transaction = connection.BeginTransaction()
' Assign transaction object for a pending local transaction.
command.Connection = connection
command.Transaction = transaction
' Execute the commands.
command.CommandText = _
"Insert into Region (RegionID, RegionDescription) VALUES (100, 'Description')"
command.ExecuteNonQuery()
command.CommandText = _
"Insert into Region (RegionID, RegionDescription) VALUES (101, 'Description')"
command.ExecuteNonQuery()
' Commit the transaction.
transaction.Commit()
Console.WriteLine("Both records are written to database.")
Catch ex As Exception
Console.WriteLine(ex.Message)
' Try to rollback the transaction
Try
transaction.Rollback()
Catch
' Do nothing here; transaction is not active.
End Try
End Try
' The connection is automatically closed when the
' code exits the Using block.
End Using
End Sub
アプリケーションは、OdbcConnection オブジェクトの BeginTransaction を呼び出して、OdbcTransaction オブジェクトを作成します。 トランザクションに関連付けられている後続のすべての操作 (トランザクションのコミットや中止など) は、OdbcTransaction オブジェクトに対して実行されます。
Connection |
トランザクションに関連付けられている OdbcConnection オブジェクトを取得するか、トランザクションが無効になった場合に |
Db |
派生クラスでオーバーライドされると、トランザクションに関連付けられている DbConnection オブジェクトを取得します。 (継承元 DbTransaction) |
Isolation |
このトランザクションの IsolationLevel を指定します。 |
Supports |
この DbTransaction インスタンスがデータベース セーブポイントをサポートしているかどうかを示す値を取得します。
|
Commit() |
データベース トランザクションをコミットします。 |
Commit |
データベース トランザクションを非同期的にコミットします。 (継承元 DbTransaction) |
Create |
リモート オブジェクトとの通信に使用されるプロキシの生成に必要なすべての関連情報を含むオブジェクトを作成します。 (継承元 MarshalByRefObject) |
Dispose() |
DbTransactionによって使用されるアンマネージ リソースを解放します。 (継承元 DbTransaction) |
Dispose(Boolean) |
DbTransaction によって使用されるアンマネージ リソースを解放し、必要に応じてマネージド リソースを解放します。 (継承元 DbTransaction) |
Dispose |
トランザクション オブジェクトを非同期的にディプスします。 (継承元 DbTransaction) |
Equals(Object) |
指定したオブジェクトが現在のオブジェクトと等しいかどうかを判断します。 (継承元 Object) |
Get |
既定のハッシュ関数として機能します。 (継承元 Object) |
Get |
古い.
このインスタンスの有効期間ポリシーを制御する現在の有効期間サービス オブジェクトを取得します。 (継承元 MarshalByRefObject) |
Get |
現在のインスタンスの Type を取得します。 (継承元 Object) |
Initialize |
古い.
このインスタンスの有効期間ポリシーを制御する有効期間サービス オブジェクトを取得します。 (継承元 MarshalByRefObject) |
Memberwise |
現在の Objectの簡易コピーを作成します。 (継承元 Object) |
Memberwise |
現在の MarshalByRefObject オブジェクトの簡易コピーを作成します。 (継承元 MarshalByRefObject) |
Release(String) |
現在のトランザクションで以前に定義されたセーブポイントを破棄します。 これにより、システムはトランザクションが終了する前に一部のリソースを再利用できます。 (継承元 DbTransaction) |
Release |
現在のトランザクションで以前に定義されたセーブポイントを破棄します。 これにより、システムはトランザクションが終了する前に一部のリソースを再利用できます。 (継承元 DbTransaction) |
Rollback() |
保留中の状態からトランザクションをロールバックします。 |
Rollback(String) |
指定したセーブポイントが確立された後に実行されたすべてのコマンドをロールバックします。 (継承元 DbTransaction) |
Rollback |
保留中の状態からトランザクションを非同期的にロールバックします。 (継承元 DbTransaction) |
Rollback |
指定したセーブポイントが確立された後に実行されたすべてのコマンドをロールバックします。 (継承元 DbTransaction) |
Save(String) |
トランザクションにセーブポイントを作成します。 これにより、セーブポイントが確立された後に実行されるすべてのコマンドをロールバックし、トランザクション状態をセーブポイントの時点の状態に復元できます。 (継承元 DbTransaction) |
Save |
トランザクションにセーブポイントを作成します。 これにより、セーブポイントが確立された後に実行されるすべてのコマンドをロールバックし、トランザクション状態をセーブポイントの時点の状態に復元できます。 (継承元 DbTransaction) |
To |
現在のオブジェクトを表す文字列を返します。 (継承元 Object) |
IDb |
トランザクションに関連付けられている DbConnection オブジェクトを取得します。トランザクションが無効になった場合は null 参照を取得します。 (継承元 DbTransaction) |
IDisposable. |
この API は製品インフラストラクチャをサポートします。コードから直接使用するものではありません。 OdbcTransaction クラスの現在のインスタンスによって使用されているリソースを解放します。 |
Configure |
非同期破棄から返されるタスクの待機を実行する方法を構成します。 |
製品 | バージョン |
---|---|
.NET | 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0 |
- OdbcDataAdapter
- OdbcConnection
- トランザクションの実行 の
.NET に関するフィードバック
.NET はオープンソース プロジェクトです。 フィードバックを提供するにはリンクを選択します。