OleDbConnection.BeginTransactionとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > OleDbConnection.BeginTransactionの意味・解説 

OleDbConnection.BeginTransaction メソッド ()

現在の IsolationLevel 値を使用してデータベース トランザクション開始します

名前空間: System.Data.OleDb
アセンブリ: System.Data (system.data.dll 内)
構文構文

Public Function BeginTransaction As
 OleDbTransaction
Dim instance As OleDbConnection
Dim returnValue As OleDbTransaction

returnValue = instance.BeginTransaction
public OleDbTransaction BeginTransaction ()
public:
OleDbTransaction^ BeginTransaction ()
public OleDbTransaction BeginTransaction ()
public function BeginTransaction () : OleDbTransaction

戻り値
新しトランザクションを表すオブジェクト

例外例外
例外種類条件

InvalidOperationException

並列トランザクションサポートされていません。

解説解説
使用例使用例

OleDbConnection と OleDbTransaction を作成する例を次に示しますBeginTransactionCommitRollback の各メソッド使い方示します

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.
        }
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

OleDbConnection.BeginTransaction メソッド (IsolationLevel)

分離レベル指定してデータベース トランザクション開始します

名前空間: System.Data.OleDb
アセンブリ: System.Data (system.data.dll 内)
構文構文

Public Function BeginTransaction ( _
    isolationLevel As IsolationLevel _
) As OleDbTransaction
Dim instance As OleDbConnection
Dim isolationLevel As IsolationLevel
Dim returnValue As OleDbTransaction

returnValue = instance.BeginTransaction(isolationLevel)
public OleDbTransaction BeginTransaction (
    IsolationLevel isolationLevel
)
public:
OleDbTransaction^ BeginTransaction (
    IsolationLevel isolationLevel
)
public OleDbTransaction BeginTransaction (
    IsolationLevel isolationLevel
)
public function BeginTransaction (
    isolationLevel : IsolationLevel
) : OleDbTransaction

パラメータ

isolationLevel

トランザクション実行する分離レベル

戻り値
新しトランザクションを表すオブジェクト

例外例外
例外種類条件

InvalidOperationException

並列トランザクションサポートされていません。

解説解説
使用例使用例

OleDbConnection と OleDbTransaction を作成する例を次に示します。BeginTransaction、CommitRollback の各メソッド使い方示します

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.
        }
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

OleDbConnection.BeginTransaction メソッド

データベース トランザクション開始します
オーバーロードの一覧オーバーロードの一覧

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

関連項目

OleDbConnection クラス
OleDbConnection メンバ
System.Data.OleDb 名前空間

その他の技術情報

データ ソースへの接続
データ ソースへの接続



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

カテゴリ一覧

すべての辞書の索引



Weblioのサービス

「OleDbConnection.BeginTransaction」の関連用語


OleDbConnection.BeginTransactionのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



OleDbConnection.BeginTransactionのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS