OleDbConnection.BeginTransaction メソッド ()
アセンブリ: System.Data (system.data.dll 内)

Dim instance As OleDbConnection Dim returnValue As OleDbTransaction returnValue = instance.BeginTransaction
新しいトランザクションを表すオブジェクト。


トランザクションは、Commit メソッドまたは Rollback メソッドを使用して、明示的にコミットまたはロールバックする必要があります。.NET Framework OLE DB 用データ プロバイダのトランザクション管理モデルを正しく実行するために、データ ソースが提供するモデルなどの他のトランザクション管理モデルは使用しないでください。

OleDbConnection と OleDbTransaction を作成する例を次に示します。BeginTransaction、Commit、Rollback の各メソッドの使い方も示します。
Public Sub ExecuteTransaction(ByVal connectionString As String) Using connection As New OleDbConnection(connectionString) Dim command As New OleDbCommand() Dim transaction As OleDbTransaction ' Set the Connection to the new OleDbConnection. command.Connection = connection ' Open the connection and execute the transaction. Try connection.Open() ' Start a local transaction with ReadCommitted isolation level. transaction = connection.BeginTransaction(IsolationLevel.ReadCommitted) ' 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
public void ExecuteTransaction(string connectionString) { using (OleDbConnection connection = new OleDbConnection(connectionString)) { OleDbCommand command = new OleDbCommand(); OleDbTransaction transaction = null; // Set the Connection to the new OleDbConnection. command.Connection = connection; // Open the connection and execute the transaction. try { connection.Open(); // Start a local transaction with ReadCommitted isolation level. transaction = connection.BeginTransaction(IsolationLevel.ReadCommitted); // 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. }
using System; using System.Data; using System.Data.OleDb; class Class1 { static void Main() { } public void ExecuteTransaction(string connectionString) { using (OleDbConnection connection = new OleDbConnection(connectionString)) { OleDbCommand command = new OleDbCommand(); OleDbTransaction transaction = null; // Set the Connection to the new OleDbConnection. command.Connection = connection; // Open the connection and execute the transaction. try { connection.Open(); // Start a local transaction with ReadCommitted isolation level. transaction = connection.BeginTransaction(IsolationLevel.ReadCommitted); // 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. }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


OleDbConnection.BeginTransaction メソッド (IsolationLevel)
アセンブリ: System.Data (system.data.dll 内)

Dim instance As OleDbConnection Dim isolationLevel As IsolationLevel Dim returnValue As OleDbTransaction returnValue = instance.BeginTransaction(isolationLevel)
戻り値
新しいトランザクションを表すオブジェクト。


トランザクションは、Commit メソッドまたは Rollback メソッドを使用して、明示的にコミットまたはロールバックする必要があります。.NET Framework OLE DB 用データ プロバイダのトランザクション管理モデルを正しく実行するために、データ ソースが提供するモデルなどの他のトランザクション管理モデルは使用しないでください。
![]() |
---|
分離レベルを指定しない場合、基になるプロバイダの既定の分離レベルが使用されます。BeginTransaction メソッドを使用して分離レベルを指定するには、isolationLevel パラメータを受け取るオーバーロードを使用します。 |

OleDbConnection と OleDbTransaction を作成する例を次に示します。BeginTransaction、Commit、Rollback の各メソッドの使い方も示します。
Public Sub ExecuteTransaction(ByVal connectionString As String) Using connection As New OleDbConnection(connectionString) Dim command As New OleDbCommand() Dim transaction As OleDbTransaction ' Set the Connection to the new OleDbConnection. 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
public void ExecuteTransaction(string connectionString) { using (OleDbConnection connection = new OleDbConnection(connectionString)) { OleDbCommand command = new OleDbCommand(); OleDbTransaction transaction = null; // Set the Connection to the new OleDbConnection. 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. }
using System; using System.Data; using System.Data.OleDb; class Class1 { static void Main() { } public void ExecuteTransaction(string connectionString) { using (OleDbConnection connection = new OleDbConnection(connectionString)) { OleDbCommand command = new OleDbCommand(); OleDbTransaction transaction = null; // Set the Connection to the new OleDbConnection. 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. }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


OleDbConnection.BeginTransaction メソッド

名前 | 説明 |
---|---|
OleDbConnection.BeginTransaction () | 現在の IsolationLevel 値を使用して、データベース トランザクションを開始します。 |
OleDbConnection.BeginTransaction (IsolationLevel) | 分離レベルを指定して、データベース トランザクションを開始します。 |
