DbConnectionStringBuilder.ConnectionString DbConnectionStringBuilder.ConnectionString DbConnectionStringBuilder.ConnectionString DbConnectionStringBuilder.ConnectionString Property

定義

DbConnectionStringBuilder に関連付けられた接続文字列を取得または設定します。Gets or sets the connection string associated with the DbConnectionStringBuilder.

public:
 property System::String ^ ConnectionString { System::String ^ get(); void set(System::String ^ value); };
public string ConnectionString { get; set; }
member this.ConnectionString : string with get, set
Public Property ConnectionString As String

プロパティ値

DbConnectionStringBuilder 内に含まれるキーと値のペアから作成された、現在の接続文字列。The current connection string, created from the key/value pairs that are contained within the DbConnectionStringBuilder. 既定値は空の文字列です。The default value is an empty string.

例外

無効な接続文字列引数が指定されています。An invalid connection string argument has been supplied.

次の例では、可能な動作のConnectionStringプロパティ。The following example demonstrates possible behaviors of the ConnectionString property. 例:The example:

  • 空の 1 つずつ、キー/値ペアを追加することで、接続文字列を作成します。DbConnectionStringBuilderします。Creates a connection string by adding key/value pairs, one at a time, to an empty DbConnectionStringBuilder.

  • 完全な接続文字列を割り当てます、ConnectionStringのプロパティ、DbConnectionStringBuilderインスタンスし、文字列内の 1 つのキー/値ペアを変更します。Assigns a complete connection string to the ConnectionString property of the DbConnectionStringBuilder instance, and modifies a single key/value pair within the string.

  • キー/値ペアの任意のセットを割り当て、ConnectionStringプロパティ (つまり、文字列をリモートで接続文字列のようなものではありません)、し、値のいずれかを変更します。Assigns an arbitrary set of key/value pairs to the ConnectionString property (that is, a string that is not anything remotely like a connection string), and modifies one of the values.

  • 無効な接続文字列を代入、ConnectionStringスローされる例外を示すプロパティです。Assigns an invalid connection string to the ConnectionString property, demonstrating the exception that is thrown.

注意

この例には、DbConnectionStringBuilder による接続文字列の操作方法を示すために、パスワードが含まれています。This example includes a password to demonstrate how DbConnectionStringBuilder works with connection strings. 実際のアプリケーションでは、Windows 認証を使用することをお勧めします。In your applications, we recommend that you use Windows Authentication. パスワードを使用する必要がある場合も、ハードコードされたパスワードをアプリケーションに含めないでください。If you must use a password, do not include a hard-coded password in your application.

static void Main()
{
    // Create a new DbConnctionStringBuilder, and add items
    // to the internal collection of key/value pairs.
    DbConnectionStringBuilder builder = new
        DbConnectionStringBuilder();
    builder.Add("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);
    // Display the contents of the connection string, which
    // will now contain all the key/value pairs delimited with
    // semicolons.
    Console.WriteLine(builder.ConnectionString);
    Console.WriteLine();
    // Clear the DbConnectionStringBuilder, and assign a complete
    // connection string to it, to demonstrate how
    // the class parses connection strings.
    builder.Clear();
    builder.ConnectionString =
        "Data Source=(local);Initial Catalog=AdventureWorks;"
        + "Integrated Security=SSPI";
    // The DbConnectionStringBuilder class has parsed the contents, 
    // so you can work with any individual key/value pair.
    builder["Data Source"] = ".";
    Console.WriteLine(builder.ConnectionString);
    Console.WriteLine();
    // Because the DbConnectionStringBuilder class doesn't 
    // validate its key/value pairs, you can use this class
    // to store any semicolon-delimited list. The following
    // snippet places an arbitrary string into the ConnectionString
    // property, changes one of the values, and then displays the
    // resulting string.
    builder.Clear();
    builder.ConnectionString =
        "Value1=10;Value2=20;Value3=30;Value4=40";
    builder["Value2"] = 25;
    Console.WriteLine(builder.ConnectionString);
    Console.WriteLine();

    builder.Clear();
    try
    {
        // Assigning an invalid connection string
        // throws an ArgumentException.
        builder.ConnectionString = "xxx";
    }
    catch (ArgumentException)
    {
        Console.WriteLine("Invalid connection string.");
    }

    Console.WriteLine();
    Console.WriteLine("Press Enter to finish.");
    Console.ReadLine();
}
Sub Main()
    ' Create a new DbConnctionStringBuilder, and add items
    ' to the internal collection of key/value pairs.
    Dim builder As New DbConnectionStringBuilder()
    builder.Add("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)

    ' Display the contents of the connection string, which
    ' will now contain all the key/value pairs delimited with
    ' semicolons.
    Console.WriteLine(builder.ConnectionString)
    Console.WriteLine()

    ' Clear the DbConnectionStringBuilder, and assign a complete
    ' connection string to it, to demonstrate how
    ' the class parses connection strings.
    builder.Clear()
    builder.ConnectionString = _
        "Data Source=(local);Initial Catalog=AdventureWorks;" & _
        "Integrated Security=SSPI"

    ' The DbConnectionStringBuilder class has parsed the contents, 
    ' so you can work with any individual key/value pair.
    builder("Data Source") = "."
    Console.WriteLine(builder.ConnectionString)
    Console.WriteLine()

    ' Because the DbConnectionStringBuilder class doesn't 
    ' validate its key/value pairs, you can use this class
    ' to store any semicolon-delimited list. The following
    ' snippet places an arbitrary string into the ConnectionString
    ' property, changes one of the values, and then displays the
    ' resulting string.
    builder.Clear()
    builder.ConnectionString = _
        "Value1=10;Value2=20;Value3=30;Value4=40"
    builder("Value2") = 25
    Console.WriteLine(builder.ConnectionString)
    Console.WriteLine()

    builder.Clear()
    Try
        ' Assigning an invalid connection string
        ' throws an ArgumentException.
        builder.ConnectionString = "xxx"

    Catch ex As ArgumentException
        Console.WriteLine("Invalid connection string.")
    End Try

    Console.WriteLine()
    Console.WriteLine("Press Enter to finish.")
    Console.ReadLine()
End Sub

注釈

このプロパティを管理するコレクション内に格納されたキー/値ペアのセミコロン区切りのリストを返します、DbConnectionStringBuilderします。This property returns a semicolon-delimited list of key/value pairs stored within the collection maintained by the DbConnectionStringBuilder. 各ペアには、キーと等号で区切られた値が含まれています。Each pair contains the key and value, separated by an equal sign. 次の例では、一般的な接続文字列を示します。The following example illustrates a typical connection string.

"Persist Security Info=False;Integrated Security=SSPI;Initial Catalog=AdventureWorks;Data Source=(local)"  

データ プロバイダーは、特定のキーと接続文字列の各プロパティの値に予想される場合があります。Data providers may expect specific keys and values for each connection string property. 、これらの値は個別に記載されています。, These values are documented individually. DbConnectionStringBuilderクラスから継承することができますが、クラスがその接続文字列に関連付けられているキー/値ペアを検証できません。The DbConnectionStringBuilder class does not validate the key/value pairs associated with its connection string, although classes that inherit from it can.

ConnectionStringのプロパティ、DbConnectionStringBuilderクラスは、一般に作成するためのメカニズムとして機能し、等号で区切られたキーと値のペアのセミコロン区切りのリストを解析します。The ConnectionString property of the DbConnectionStringBuilder class acts generally as a mechanism for creating and parsing semicolon-delimited lists of key/value pairs separated with equal signs. 検証なしまたは接続文字列に固有の他のサポートを提供します。It provides no validation or other support specific to connection strings. 項目を追加する場合、 DbConnectionStringBuilder 、コレクション、ConnectionStringプロパティ変更が反映されます。If you add items to the DbConnectionStringBuilder collection, the ConnectionString property will reflect the changes. 値を割り当てる場合、ConnectionStringプロパティ、DbConnectionStringBuilderセミコロンと等号 (=) の区切り記号を使用して、値の解析を試みます。If you assign a value to the ConnectionString property, the DbConnectionStringBuilder will try to parse the value, using the semicolon and equal-sign delimiters.

適用対象

こちらもご覧ください