OleDbConnection クラスとは? わかりやすく解説

OleDbConnection クラス

データ ソースへの開いた接続表します

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

Public NotInheritable Class
 OleDbConnection
    Inherits DbConnection
    Implements ICloneable, IDbConnection, IDisposable
Dim instance As OleDbConnection
public sealed class OleDbConnection : DbConnection,
 ICloneable, IDbConnection, IDisposable
public ref class OleDbConnection sealed : public
 DbConnection, ICloneable, IDbConnection, IDisposable
public final class OleDbConnection extends
 DbConnection implements ICloneable, IDbConnection, 
    IDisposable
public final class OleDbConnection extends
 DbConnection implements ICloneable, IDbConnection, 
    IDisposable
解説解説

OleDbConnection オブジェクトは、データ ソースへの一意接続表しますクライアント/サーバー データベース システムでは、サーバーへのネットワーク接続相当しますネイティブOLE DB プロバイダサポートする機能によっては、OleDbConnection オブジェクト一部メソッド、またはプロパティ利用できないことあります

OleDbConnectionインスタンス作成すると、すべてのプロパティ初期値設定されます。これらの初期値一覧については、OleDbConnection コンストラクタトピック参照してください

OleDbConnection は、適用範囲外では閉じられません。そのため、Close または Dispose呼び出すか、OleDbConnection オブジェクトUsing ステートメント内に記述することによって、明示的に接続閉じる必要があります

メモメモ

パフォーマンスの高いアプリケーション配置するには、接続プール使用する必要があります.NET Framework OLE DBデータ プロバイダ使用する場合は、プロバイダ接続プール自動的に管理するため、この機能有効にする必要はありません。.NET Framework OLE DBデータ プロバイダによる接続プール使用方法詳細については、「接続プールについて」を参照してください

OleDbCommand を実行したメソッドで、致命的な OleDbException (SQL Server重大度レベル20 以上など) が発生した場合は、OleDbConnection閉じられることがあります。ただし、ユーザー接続を再び開いて、処理を継続できます

OleDbConnection オブジェクトインスタンス作成するアプリケーションは、宣言セキュリティまたは強制セキュリティ要求設定することによって、直接的または間接的な呼び出し元すべてに対してコードへの適切なアクセス許可要求できますOleDbConnection は、OleDbPermission オブジェクト使用してセキュリティ要求作成しますユーザーは、OleDbPermissionAttribute オブジェクト使用してコード適切なアクセス許可設定されているかどうか確認できますまた、ユーザーおよび管理者は、コード アクセス セキュリティ ポリシー ツール (Caspol.exe) を使用してコンピュータユーザーエンタープライズの各レベルセキュリティ ポリシー変更できます詳細については、「コード アクセス セキュリティADO.NET」を参照してください

データ サーバーから受け取警告メッセージ情報メッセージの処理の詳細については、「接続イベント使用」を参照してください

使用例使用例

OleDbCommandOleDbConnection作成する例を次に示しますOleDbConnection開かれOleDbCommand 用の Connection として設定されます。この例では、次に、ExecuteNonQuery を呼び出し接続閉じます。この例では、ExecuteNonQuery に、接続文字列SQL INSERT ステートメントクエリ文字列渡されます。

Public Sub InsertRow(ByVal
 connectionString As String, _
    ByVal insertSQL As String)

    Using connection As New OleDbConnection(connectionString)
        ' The insertSQL string contains a SQL statement that
        ' inserts a new row in the source table.
        Dim command As New
 OleDbCommand(insertSQL)

        ' Set the Connection to the new OleDbConnection.
        command.Connection = connection

        ' Open the connection and execute the insert command.
        Try
            connection.Open()
            command.ExecuteNonQuery()
        Catch ex As Exception
            Console.WriteLine(ex.Message)
        End Try
        ' The connection is automatically closed when the
        ' code exits the Using block.
    End Using
End Sub
public void InsertRow(string
 connectionString, string insertSQL)
{
    using (OleDbConnection connection = new
 OleDbConnection(connectionString))
    {
        // The insertSQL string contains a SQL statement that
        // inserts a new row in the source table.
        OleDbCommand command = new OleDbCommand(insertSQL);

        // Set the Connection to the new OleDbConnection.
        command.Connection = connection;

        // Open the connection and execute the insert command.
        try
        {
            connection.Open();
            command.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
        // 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 InsertRow(string
 connectionString, string insertSQL)
    {
        using (OleDbConnection connection = new
 OleDbConnection(connectionString))
        {
            // The insertSQL string contains a SQL statement that
            // inserts a new row in the source table.
            OleDbCommand command = new OleDbCommand(insertSQL);

            // Set the Connection to the new OleDbConnection.
            command.Connection = connection;

            // Open the connection and execute the insert command.
            try
            {
                connection.Open();
                command.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            // The connection is automatically closed when the
            // code exits the using block.
        }
継承階層継承階層
System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Data.Common.DbConnection
        System.Data.OleDb.OleDbConnection
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



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

辞書ショートカット

すべての辞書の索引

「OleDbConnection クラス」の関連用語

OleDbConnection クラスのお隣キーワード
検索ランキング

   

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



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

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

©2025 GRAS Group, Inc.RSS