OleDbConnectionStringBuilderとは? わかりやすく解説

OleDbConnectionStringBuilder クラス

メモ : このクラスは、.NET Framework version 2.0新しく追加されたものです。

OleDbConnection クラス使用する接続文字列内容作成管理簡単に実行できるようにします。

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

Public NotInheritable Class
 OleDbConnectionStringBuilder
    Inherits DbConnectionStringBuilder
Dim instance As OleDbConnectionStringBuilder
public sealed class OleDbConnectionStringBuilder
 : DbConnectionStringBuilder
public ref class OleDbConnectionStringBuilder
 sealed : public DbConnectionStringBuilder
public final class OleDbConnectionStringBuilder
 extends DbConnectionStringBuilder
public final class OleDbConnectionStringBuilder
 extends DbConnectionStringBuilder
解説解説

接続文字列ビルダにより、クラスプロパティメソッド使用して構文的に正確な接続文字列プログラム作成したり、既存接続文字列解析および再構築したりできます接続文字列ビルダは、OLE DB 接続サポートする既知キー/値ペア対応した厳密に指定されプロパティ提供するほか、開発者が他の接続文字列に対して任意のキー/値ペア追加することもできますOleDbConnectionStringBuilder クラスは、ICustomTypeDescriptor インターフェイス実装ます。つまり、クラスVisual Studio .NET デザイナデザイン時に連動するということです。Visual Studio .NETデザイナ使用して厳密に指定されDataSet および厳密に指定され接続作成することにより、厳密に指定され接続文字列ビルダ クラスによって、その型に関連付けられたプロパティ表示されるほか、既知キーに共通の値をマップするためのコンバータ使用できるようになります

接続文字列アプリケーション内で生成する必要がある場合OleDbConnectionStringBuilder クラス使用して接続文字列生成および修正できますまた、このクラス利用することで、アプリケーション構成ファイル格納される接続文字列管理容易になりますOleDbConnectionStringBuilder によって実行されるチェックは、既知キー/値ペア限定されます。たがって、このクラス使用した場合無効な接続文字列生成される場合あります既知キーと、OleDbConnectionStringBuilder クラス内の対応するプロパティ、およびその既定値の一覧を次の表に示します。これらの特定の値以外にも、開発者任意のキー/値ペアを、OleDbConnectionStringBuilderインスタンス内に保持されるコレクション追加できます

Item プロパティは、安全ではないエントリの挿入試みられ場合も、適切に処理します。たとえば、次のコードでは、既定Item プロパティ (C# ではインデクサ) を使用することで、入れ子になったキー/値ペアが適切にエスケープされています。

Dim builder As _
    New System.Data.OleDb.OleDbConnectionStringBuilder
builder("Provider") = "Microsoft.Jet.OLEDB.4.0"
builder("Data Source") = "C:\Sample.mdb"
builder("User Id") = "Admin;NewValue=Bad"
System.Data.OleDb.OleDbConnectionStringBuilder builder = 
    new System.Data.OleDb.OleDbConnectionStringBuilder();
builder["Provider"] = "Microsoft.Jet.OLEDB.4.0";
builder["Data Source"] = "C:\\Sample.mdb";
builder["User Id"] = "Admin;NewValue=Bad";

結果次の接続文字列になり、無効な値は安全な方法処理されます。

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Sample.mdb;User ID="Admin;NewValue=Bad"
使用例使用例

次のコンソール アプリケーションでは、いくつかの OLE DB データベース使用される接続文字列作成します最初にMicrosoft Access データベース用の接続文字列作成した後、IBM DB2 データベース用の接続文字列作成しますまた、既存接続文字列解析し接続文字列内容に対して各種操作を行う例が示されています。

メモメモ

この例には、OleDbConnectionStringBuilder接続文字列どのように連携するかを示すパスワード含まれています。アプリケーションでは、Windows 認証使用お勧めます。パスワード使用する必要がある場合は、ハードコーディングされたパスワードアプリケーション組み込まないください

Imports System.Data.OleDb    
Imports System.Collections

Module Module1
  Sub Main()
    Dim builder As New OleDbConnectionStringBuilder()
    builder.ConnectionString = "Data Source=C:\Sample.mdb"

    ' Call the Add method to explicitly add key/value
    ' pairs to the internal collection.
    builder.Add("Provider", "Microsoft.Jet.Oledb.4.0")
    builder.Add("Jet OLEDB:Database Password", "MyPassword!")
    builder.Add("Jet OLEDB:System Database", "C:\Workgroup.mdb")

    ' Set up row-level locking.
    builder.Add("Jet OLEDB:Database Locking Mode",
 1)

    Console.WriteLine(builder.ConnectionString)
    Console.WriteLine()

    ' Clear current values and reset known keys to their
    ' default values.
    builder.Clear()

    ' Pass the OleDbConnectionStringBuilder an existing 
    ' connection string, and you can retrieve and
    ' modify any of the elements.
    builder.ConnectionString = _
        "Provider=DB2OLEDB;Network Transport Library=TCPIP;"
 & _
        "Network Address=192.168.0.12;Initial Catalog=DbAdventures;"
 & _
        "Package Collection=SamplePackage;Default Schema=SampleSchema;"

    Console.WriteLine("Network Address = " & builder("Network
 Address").ToString())
    Console.WriteLine()

    ' Modify existing items.
    builder("Package Collection") = "NewPackage"
    builder("Default Schema") = "NewSchema"

    ' Call the Remove method to remove items from 
    ' the collection of key/value pairs.
    builder.Remove("User ID")

    ' Note that calling Remove on a nonexistent item does not
    ' throw an exception.
    builder.Remove("BadItem")
    Console.WriteLine(builder.ConnectionString)
    Console.WriteLine()

    ' The Item property is the default for the class, 
    ' and setting the Item property adds the value, if 
    ' necessary.
    builder("User ID") = "SampleUser"
    builder("Password") = "SamplePassword"
    Console.WriteLine(builder.ConnectionString)

    Console.WriteLine("Press Enter to finish.")
    Console.ReadLine()
  End Sub
End Module
using System.Data.OleDb;

class Program
{
    static void Main(string[]
 args)
    {
        OleDbConnectionStringBuilder builder = new OleDbConnectionStringBuilder();
        builder.ConnectionString = @"Data Source=C:\Sample.mdb";

        // Call the Add method to explicitly add key/value
        // pairs to the internal collection.
        builder.Add("Provider", "Microsoft.Jet.Oledb.4.0");
        builder.Add("Jet OLEDB:Database Password", "MyPassword!");
        builder.Add("Jet OLEDB:System Database", @"C:\Workgroup.mdb");

        // Set up row-level locking.
        builder.Add("Jet OLEDB:Database Locking Mode", 1);

        Console.WriteLine(builder.ConnectionString);
        Console.WriteLine();

        // Clear current values and reset known keys to their
        // default values.
        builder.Clear();

        // Pass the OleDbConnectionStringBuilder an existing 
        // connection string, and you can retrieve and
        // modify any of the elements.
        builder.ConnectionString =
            "Provider=DB2OLEDB;Network Transport Library=TCPIP;" +
            "Network Address=192.168.0.12;Initial Catalog=DbAdventures;"
 +
            "Package Collection=SamplePackage;Default Schema=SampleSchema;";

        Console.WriteLine("Network Address = " + builder["Network
 Address"].ToString());
        Console.WriteLine();

        // Modify existing items.
        builder["Package Collection"] = "NewPackage";
        builder["Default Schema"] = "NewSchema";

        // Call the Remove method to remove items from 
        // the collection of key/value pairs.
        builder.Remove("User ID");

        // Note that calling Remove on a nonexistent item does not
        // throw an exception.
        builder.Remove("BadItem");
        Console.WriteLine(builder.ConnectionString);
        Console.WriteLine();

        // Setting the indexer adds the value, if 
        // necessary.
        builder["User ID"] = "SampleUser";
        builder["Password"] = "SamplePassword";
        Console.WriteLine(builder.ConnectionString);

        Console.WriteLine("Press Enter to finish.");
        Console.ReadLine();
    }
}
継承階層継承階層
System.Object
   System.Data.Common.DbConnectionStringBuilder
    System.Data.OleDb.OleDbConnectionStringBuilder
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

OleDbConnectionStringBuilder コンストラクタ ()


OleDbConnectionStringBuilder コンストラクタ

OleDbConnectionStringBuilder クラス新しインスタンス初期化します。 接続文字列使用
オーバーロードの一覧オーバーロードの一覧

名前 説明
OleDbConnectionStringBuilder () OleDbConnectionStringBuilder クラス新しインスタンス初期化します。
OleDbConnectionStringBuilder (String) OleDbConnectionStringBuilder クラス新しインスタンス初期化します。引数渡した接続文字列によって、インスタンス内部的接続情報データ提供されます。
参照参照

関連項目

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

その他の技術情報

Building Connection Strings
接続文字列使用
接続文字列使用

OleDbConnectionStringBuilder コンストラクタ (String)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

OleDbConnectionStringBuilder クラス新しインスタンス初期化します。引数渡した接続文字列によって、インスタンス内部的接続情報データ提供されます。

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

Public Sub New ( _
    connectionString As String _
)
Dim connectionString As String

Dim instance As New OleDbConnectionStringBuilder(connectionString)
public OleDbConnectionStringBuilder (
    string connectionString
)
public:
OleDbConnectionStringBuilder (
    String^ connectionString
)
public OleDbConnectionStringBuilder (
    String connectionString
)
public function OleDbConnectionStringBuilder
 (
    connectionString : String
)

パラメータ

connectionString

この情報を基にオブジェクト内部的接続情報生成されます。この情報解析されキー/値のペアが生成されます。

例外例外
例外種類条件

ArgumentException

接続文字列正し書式になっていません。たとえば、キー/値ペアに "=" が欠落していることが考えられます。

解説解説
使用例使用例

次の例では、複数OleDbConnectionStringBuilder インスタンス作成しそれぞれの場合について異な接続文字列コンストラクタ渡してます。接続使用するプロバイダ設定することによって、定義済みキー/値ペアがオブジェクトコレクション内でどのように変わるかに注意してください

メモメモ

この例には、OleDbConnectionStringBuilder接続文字列どのように連携するかを示すパスワード含まれています。アプリケーションでは、Windows 認証使用お勧めます。パスワード使用する必要がある場合は、ハードコーディングされたパスワードアプリケーション組み込まないください

Imports System.Data.OleDb    

Module Module1
  Sub Main()
    Try
      ' Build an empty instance, just to see
      ' the contents of the keys.
      DumpBuilderContents("")

      ' Create a SQL Server connection string.
      DumpBuilderContents("Provider=sqloledb;Data Source=(local);"
 & _
       "Initial Catalog=AdventureWorks;" & _
       "User Id=ab;Password=Password@1")

      ' Create an Access connection string.
      DumpBuilderContents("Provider=Microsoft.Jet.OLEDB.4.0;"
 & _
       "Data Source=C:\Sample.mdb")

      ' Create an Oracle connection string.
      DumpBuilderContents("Provider=msdaora;Data Source=SomeOracleDb;"
 & _
       "User Id=userName;Password=Pass@word1;")

      ' Create a Sybase connection string.
      DumpBuilderContents("Provider=ASAProv;Data source=myASA")

      Console.WriteLine("Press any key to finish.")
      Console.ReadLine()

    Catch ex As System.ArgumentException
      Console.WriteLine("Error: " & ex.Message)
    End Try
  End Sub

  Private Sub DumpBuilderContents(ByVal
 connectString As String)
    Dim builder As New OleDbConnectionStringBuilder(connectString)
    Console.WriteLine("=================")
    Console.WriteLine("Original connectString   = "
 & connectString)
    Console.WriteLine("builder.ConnectionString = "
 & builder.ConnectionString)
    For Each key As String
 In builder.Keys
      Console.WriteLine(key & "=" & builder.Item(key).ToString)
    Next
  End Sub
End Module
using System.Data.OleDb;

class Program
{
    static void Main()
    {
        try
        {
            // Build an empty instance, just to see
            // the contents of the keys.
            DumpBuilderContents("");

            // Create a SQL Server connection string.
            DumpBuilderContents("Provider=sqloledb;Data Source=(local);"
 +
                "Initial Catalog=AdventureWorks;" +
                "User Id=ab;Password=Password@1");

            // Create an Access connection string.
            DumpBuilderContents("Provider=Microsoft.Jet.OLEDB.4.0;" +
                @"Data Source=C:\Sample.mdb");

            // Create an Oracle connection string.
            DumpBuilderContents("Provider=msdaora;Data Source=SomeOracleDb;"
 +
                "User Id=userName;Password=Pass@word1;");

            // Create an Sybase connection string.
            DumpBuilderContents("Provider=ASAProv;Data source=myASA");

            Console.WriteLine("Press any key to finish.");
            Console.ReadLine();

        }
        catch (System.ArgumentException ex)
        {

            Console.WriteLine("Error: " + ex.Message);
        }
    }

    private static void
 DumpBuilderContents(string connectString)
    {
        OleDbConnectionStringBuilder builder =
            new OleDbConnectionStringBuilder(connectString);
        Console.WriteLine("=================");
        Console.WriteLine("Original connectString   = " + connectString);
        Console.WriteLine("builder.ConnectionString = " + builder.ConnectionString);
        foreach (string key in
 builder.Keys)
        {
            Console.WriteLine(key + "=" + builder[key].ToString());
        }
    }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
OleDbConnectionStringBuilder クラス
OleDbConnectionStringBuilder メンバ
System.Data.OleDb 名前空間
その他の技術情報
Building Connection Strings
接続文字列使用

OleDbConnectionStringBuilder プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ BrowsableConnectionString  ConnectionString プロパティVisual Studio デザイナ表示できるかどうか指定する値を取得または設定します。 ( DbConnectionStringBuilder から継承されます。)
パブリック プロパティ ConnectionString  DbConnectionStringBuilder に関連付けられる接続文字列取得または設定します。 ( DbConnectionStringBuilder から継承されます。)
パブリック プロパティ Count  ConnectionString プロパティ格納されている、現在のキー数を取得します。 ( DbConnectionStringBuilder から継承されます。)
パブリック プロパティ DataSource 接続先のデータ ソースの名前を取得または設定します
パブリック プロパティ FileName データ ソースへの接続使用する汎用データ リンク (UDL) ファイルの名前を取得または設定します
パブリック プロパティ IsFixedSize  DbConnectionStringBuilder固定サイズかどうかを示す値を取得します。 ( DbConnectionStringBuilder から継承されます。)
パブリック プロパティ IsReadOnly  DbConnectionStringBuilder読み取り専用かどうかを示す値を取得します。 ( DbConnectionStringBuilder から継承されます。)
パブリック プロパティ Item オーバーライドされます指定したキー関連付けられている値を取得または設定しますC# では、このプロパティインデクサです。
パブリック プロパティ Keys オーバーライドされます。 OleDbConnectionStringBuilder 内のキー格納している ICollection を取得します
パブリック プロパティ OleDbServices 接続文字列の中で OLE DB Services キー対応する値を取得または設定します
パブリック プロパティ PersistSecurityInfo 接続開いているか、開いている状態になったことがある場合に、パスワードなどの機密性の高い情報接続文字列一部として返すかどうかを示すブール値を取得または設定します
パブリック プロパティ Provider 接続文字列関連付けられたデータ プロバイダの名前を内部的に保持する文字列取得または設定します
パブリック プロパティ Values  DbConnectionStringBuilder 内の値を格納している ICollection取得します。 ( DbConnectionStringBuilder から継承されます。)
参照参照

関連項目

OleDbConnectionStringBuilder クラス
System.Data.OleDb 名前空間

その他の技術情報

Building Connection Strings
接続文字列使用

OleDbConnectionStringBuilder メソッド


パブリック メソッドパブリック メソッド

( プロテクト メソッド参照)
  名前 説明
パブリック メソッド Add  指定したキーおよび値を持つエントリを DbConnectionStringBuilder に追加します。 ( DbConnectionStringBuilder から継承されます。)
パブリック メソッド AppendKeyValuePair  オーバーロードされます効率的かつ安全に既存の StringBuilder オブジェクトキーと値を追加できます。 ( DbConnectionStringBuilder から継承されます。)
パブリック メソッド Clear オーバーライドされます。 OleDbConnectionStringBuilder インスタンス内容消去します。
パブリック メソッド ContainsKey オーバーライドされますOleDbConnectionStringBuilder特定のキー格納されているかどうか判断します
パブリック メソッド Equals  オーバーロードされます2 つObject インスタンス等しかどうか判断します。 ( Object から継承されます。)
パブリック メソッド EquivalentTo  この DbConnectionStringBuilder オブジェクト内の接続情報と、指定したオブジェクト内の接続情報比較します。 ( DbConnectionStringBuilder から継承されます。)
パブリック メソッド GetHashCode  特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用適してます。 ( Object から継承されます。)
パブリック メソッド GetType  現在のインスタンスType取得します。 ( Object から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数Object インスタンス同一かどうか判断します。 ( Object から継承されます。)
パブリック メソッド Remove オーバーライドされます指定したキーを持つエントリを OleDbConnectionStringBuilder インスタンスか削除します
パブリック メソッド ShouldSerialize  指定されキーが、この DbConnectionStringBuilder インスタンス存在するかどうか示します。 ( DbConnectionStringBuilder から継承されます。)
パブリック メソッド ToString  この DbConnectionStringBuilder関連付けられている接続文字列返します。 ( DbConnectionStringBuilder から継承されます。)
パブリック メソッド TryGetValue オーバーライドされます指定されキー対応する値を OleDbConnectionStringBuilderインスタンスか取得します
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

OleDbConnectionStringBuilder クラス
System.Data.OleDb 名前空間

その他の技術情報

Building Connection Strings
接続文字列使用

OleDbConnectionStringBuilder メンバ

OleDbConnection クラス使用する接続文字列内容作成管理簡単に実行できるようにします。

OleDbConnectionStringBuilder データ型公開されるメンバを以下の表に示します


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド OleDbConnectionStringBuilder オーバーロードされます。 OleDbConnectionStringBuilder クラス新しインスタンス初期化します。
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ BrowsableConnectionString  ConnectionString プロパティVisual Studio デザイナ表示できるかどうか指定する値を取得または設定します。(DbConnectionStringBuilder から継承されます。)
パブリック プロパティ ConnectionString  DbConnectionStringBuilder関連付けられる接続文字列取得または設定します。(DbConnectionStringBuilder から継承されます。)
パブリック プロパティ Count  ConnectionString プロパティ格納されている、現在のキー数を取得します。(DbConnectionStringBuilder から継承されます。)
パブリック プロパティ DataSource 接続先のデータ ソースの名前を取得または設定します
パブリック プロパティ FileName データ ソースへの接続使用する汎用データ リンク (UDL) ファイルの名前を取得または設定します
パブリック プロパティ IsFixedSize  DbConnectionStringBuilder固定サイズかどうかを示す値を取得します。(DbConnectionStringBuilder から継承されます。)
パブリック プロパティ IsReadOnly  DbConnectionStringBuilder読み取り専用かどうかを示す値を取得します。(DbConnectionStringBuilder から継承されます。)
パブリック プロパティ Item オーバーライドされます指定したキー関連付けられている値を取得または設定しますC# では、このプロパティインデクサです。
パブリック プロパティ Keys オーバーライドされますOleDbConnectionStringBuilder 内のキー格納している ICollection を取得します
パブリック プロパティ OleDbServices 接続文字列の中で OLE DB Services キー対応する値を取得または設定します
パブリック プロパティ PersistSecurityInfo 接続開いているか、開いている状態になったことがある場合に、パスワードなどの機密性の高い情報接続文字列一部として返すかどうかを示すブール値を取得または設定します
パブリック プロパティ Provider 接続文字列関連付けられたデータ プロバイダの名前を内部的に保持する文字列取得または設定します
パブリック プロパティ Values  DbConnectionStringBuilder 内の値を格納している ICollection取得します。(DbConnectionStringBuilder から継承されます。)
パブリック メソッドパブリック メソッド
( プロテクト メソッド参照)
  名前 説明
パブリック メソッド Add  指定したキーおよび値を持つエントリを DbConnectionStringBuilder に追加します。 (DbConnectionStringBuilder から継承されます。)
パブリック メソッド AppendKeyValuePair  オーバーロードされます効率的かつ安全に既存の StringBuilder オブジェクトキーと値を追加できます。 (DbConnectionStringBuilder から継承されます。)
パブリック メソッド Clear オーバーライドされますOleDbConnectionStringBuilder インスタンス内容消去します。
パブリック メソッド ContainsKey オーバーライドされますOleDbConnectionStringBuilder特定のキー格納されているかどうか判断します
パブリック メソッド Equals  オーバーロードされます2 つObject インスタンス等しかどうか判断します。 (Object から継承されます。)
パブリック メソッド EquivalentTo  この DbConnectionStringBuilder オブジェクト内の接続情報と、指定したオブジェクト内の接続情報比較します。 (DbConnectionStringBuilder から継承されます。)
パブリック メソッド GetHashCode  特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用適してます。 (Object から継承されます。)
パブリック メソッド GetType  現在のインスタンスType取得します。 (Object から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数Object インスタンス同一かどうか判断します。 (Object から継承されます。)
パブリック メソッド Remove オーバーライドされます指定したキーを持つエントリを OleDbConnectionStringBuilder インスタンスか削除します
パブリック メソッド ShouldSerialize  指定されキーが、この DbConnectionStringBuilder インスタンス存在するかどうか示します。 (DbConnectionStringBuilder から継承されます。)
パブリック メソッド ToString  この DbConnectionStringBuilder関連付けられている接続文字列返します。 (DbConnectionStringBuilder から継承されます。)
パブリック メソッド TryGetValue オーバーライドされます指定されキー対応する値を OleDbConnectionStringBuilderインスタンスか取得します
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

OleDbConnectionStringBuilder クラス
System.Data.OleDb 名前空間

その他の技術情報

Building Connection Strings
接続文字列使用



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

辞書ショートカット

すべての辞書の索引

「OleDbConnectionStringBuilder」の関連用語

OleDbConnectionStringBuilderのお隣キーワード
検索ランキング

   

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



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

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

©2025 GRAS Group, Inc.RSS