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

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

DbConnectionStringBuilder クラス

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

厳密に指定され接続文字列ビルダ基本クラス提供します

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

Public Class DbConnectionStringBuilder
    Implements IDictionary, ICollection, IEnumerable, ICustomTypeDescriptor
Dim instance As DbConnectionStringBuilder
public class DbConnectionStringBuilder : IDictionary,
 ICollection, IEnumerable, 
    ICustomTypeDescriptor
public ref class DbConnectionStringBuilder
 : IDictionary, ICollection, IEnumerable, 
    ICustomTypeDescriptor
public class DbConnectionStringBuilder implements
 IDictionary, ICollection, 
    IEnumerable, ICustomTypeDescriptor
public class DbConnectionStringBuilder implements
 IDictionary, ICollection, 
    IEnumerable, ICustomTypeDescriptor
解説解説

DbConnectionStringBuilder クラスにより、厳密に指定され接続文字列ビルダ (SqlConnectionStringBuilder や OleDbConnectionStringBuilder など) の派生元となる基本クラス得られます。この接続文字列ビルダ使用して正確な構文接続文字列プログラムか作成したり、既存接続文字列解析再構築したりできます

DbConnectionStringBuilderデータベース選ばない方法定義されいました。System.Data.Common 名前空間追加されたため、任意のデータベースに対して有効な接続文字列構築するためにプログラム使用できる基本クラスが必要です。つまり、DbConnectionStringBuilder クラスによってユーザー任意のキー/値ペア割り当て生成され接続文字列厳密に指定されプロバイダに渡すことができます.NET Framework一部となっているすべてのデータ プロバイダが、DbConnectionStringBuilder から継承され厳密に指定されクラス提供します。そのクラスとは、SqlConnectionStringBuilder、OracleConnectionStringBuilder、OdbcConnectionStringBuilder、OleDbConnectionStringBuilder です。

任意のプロバイダ接続文字列構築割り当て編集できます特定のキー/値ペアサポートするプロバイダ場合接続文字列ビルダによってそのペア対応する厳密に指定されプロパティ得られます。未知の値をサポートする機能要求されるプロバイダサポートするために、任意のキー/値ペア指定することもできます

DbConnectionStringBuilder クラスは、ICustomTypeDescriptor インターフェイス実装ます。つまり、このクラスデザイン時に Visual Studio デザイナ組み合わせて使用できますデザイナ使用してVisual Studio厳密に指定されDataSet厳密に指定され接続構築すると、厳密に指定され接続文字列ビルダ クラスでは、その型に関連付けられたプロパティ表示され、さらに既知キーに共通の値を割り当てられるコンバータ得られます。

接続文字列アプリケーション内で生成する必要がある場合DbConnectionStringBuilder クラス、またはその厳密に指定され派生クラス使用して接続文字列構築した修正したできますまた、DbConnectionStringBuilder クラス利用することで、アプリケーション構成ファイル格納される接続文字列管理容易になります

厳密に指定され接続文字列ビルダ クラス、または DbConnectionStringBuilder クラス使用して接続文字列作成できますDbConnectionStringBuilder では、キー/値ペアが有効であるかどうかチェック実行されません。したがって、このクラス使用する無効な接続文字列作成される可能性ありますSqlConnectionStringBuilder では、SQL Serverサポートされキー/値ペアのみがサポートされます。無効なペア追加しようとすると、例外スローさます。

悪意のあるエントリ挿入しようとする操作は、Add メソッドItem プロパティによって処理されます。たとえば、入れ子になったキー/値ペア次のコードによって適切にエスケープされます

[Visual Basic]

Dim builder As New System.Data.Common.DbConnectionStringBuilder
builder("Data Source") = "(local)"
builder("integrated sSecurity") = True
builder("Initial Catalog") = "AdventureWorks;NewValue=Bad"

[C#]

System.Data.Common.DbConnectionStringBuilder builder = 
    new System.Data.Common.DbConnectionStringBuilder();
builder["Data Source"] = "(local)";
builder["integrated Security"] = true;
builder["Initial Catalog"] = "AdventureWorks;NewValue=Bad";

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

data source=(local);integrated security=True;
initial catalog="AdventureWorks;NewValue=Bad"
使用例使用例

Microsoft Jet データベースMicrosoft SQL Server 2005 データベース用に、2 つ接続文字列構築するコンソール アプリケーション次に示します。どちらの接続文字列場合も、このコードでは汎用の DbConnectionStringBuilder クラス使用して接続文字列作成しDbConnectionStringBuilder インスタンスの ConnectionString プロパティ厳密に指定され接続クラスコンストラクタ渡してます。この動作必須ではありません。コードでは、厳密に指定され接続文字列ビルダインスタンス個別作成することもできます。さらにこの例では、既存接続文字列解析し接続文字列内容に対して各種操作を行う例が示されています。

Sub Main()
    Dim builder As New DbConnectionStringBuilder()
    builder.ConnectionString = "Data Source=c:\MyData\MyDb.mdb"
    builder.Add("Provider", "Microsoft.Jet.Oledb.4.0")
    builder.Add("Jet OLEDB:Database Password", "*******")
    builder.Add("Jet OLEDB:System Database", _
        "c:\MyData\Workgroup.mdb")

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

    ' Note that the DbConnectionStringBuilder class 
    ' is database agnostic, and it's possible to 
    ' build any type of connection string using 
    ' this class.
    ' Notice that the ConnectionString property may have been 
    ' formatted by the DbConnectionStringBuilder class.

    Dim oledbConnect As New
 _
        OleDbConnection(builder.ConnectionString)
    Console.WriteLine(oledbConnect.ConnectionString)

    ' Use the same DbConnectionStringBuilder to create 
    ' a SqlConnection object.
    builder.Clear()
    builder.Add("integrated security", True)
    builder.Add("Initial Catalog", "AdventureWorks")
    builder.Add("Data Source", "(local)")

    Dim sqlConnect As New
 SqlConnection(builder.ConnectionString)
    Console.WriteLine(sqlConnect.ConnectionString)

    ' Pass the DbConnectionStringBuilder an existing 
    ' connection string, and you can retrieve and
    ' modify any of the elements.
    builder.ConnectionString = _
        "server=(local);user id=*******;" & _
        "password=*******;initial catalog=AdventureWorks"
    builder.Item("Server") = "."
    builder.Remove("User ID")

    ' Note that calling Remove on a nonexistent item doesn't
    ' throw an exception.
    builder.Remove("BadItem")

    ' The Item property is the default for the class, 
    ' and setting the Item property adds the value if 
    ' necessary.
    builder("Integrated Security") = True
    builder.Remove("password")
    builder.Item("User ID") = "Hello"
    Console.WriteLine(builder.ConnectionString)

    Console.WriteLine("Press Enter to finish.")
    Console.ReadLine()
End Sub
static void Main()
{
    DbConnectionStringBuilder builder =
        new DbConnectionStringBuilder();
    builder.ConnectionString = @"Data Source=c:\MyData\MyDb.mdb";
    builder.Add("Provider", "Microsoft.Jet.Oledb.4.0");
    builder.Add("Jet OLEDB:Database Password", "*******");
    builder.Add("Jet OLEDB:System Database",
        @"c:\MyData\Workgroup.mdb");
    // Set up row-level locking.
    builder.Add("Jet OLEDB:Database Locking Mode", 1);

    // The DbConnectionStringBuilder class 
    // is database agnostic, so it's possible to 
    // build any type of connection string using 
    // this class.

    // The ConnectionString property may have been 
    // formatted by the DbConnectionStringBuilder class.
    OleDbConnection oledbConnect = new
        OleDbConnection(builder.ConnectionString);
    Console.WriteLine(oledbConnect.ConnectionString);

    // Use the same DbConnectionStringBuilder to create 
    // a SqlConnection object.
    builder.Clear();
    builder.Add("integrated security", true);
    builder.Add("Initial Catalog", "AdventureWorks");
    builder.Add("Data Source", "(local)");

    SqlConnection sqlConnect = new
        SqlConnection(builder.ConnectionString);
    Console.WriteLine(sqlConnect.ConnectionString);

    // Pass the DbConnectionStringBuilder an existing 
    // connection string, and you can retrieve and
    // modify any of the elements.
    builder.ConnectionString = "server=(local);user id=*******;" +
        "password=*******;initial catalog=AdventureWorks";
    builder["Server"] = ".";
    builder.Remove("User ID");

    // Note that calling Remove on a nonexistent item doesn't
    // throw an exception.
    builder.Remove("BadItem");

    // Setting the indexer adds the value if 
    // necessary.
    builder["Integrated Security"] = true;
    builder.Remove("password");
    builder["User ID"] = "Hello";
    Console.WriteLine(builder.ConnectionString);

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


このページでは「.NET Framework クラス ライブラリ リファレンス」からDbConnectionStringBuilder クラスを検索した結果を表示しています。
Weblioに収録されているすべての辞書からDbConnectionStringBuilder クラスを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からDbConnectionStringBuilder クラス を検索

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

辞書ショートカット

すべての辞書の索引

「DbConnectionStringBuilder クラス」の関連用語

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

   

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



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

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

©2025 GRAS Group, Inc.RSS