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

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > 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) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



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

辞書ショートカット

すべての辞書の索引

「OleDbConnectionStringBuilder クラス」の関連用語

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

   

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



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

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

©2025 GRAS Group, Inc.RSS