SqlConnectionStringBuilder.Clear Method

Definition

Clears the contents of the SqlConnectionStringBuilder instance.

C#
public override void Clear ();

Examples

The following example demonstrates calling the Clear method. This example populates the SqlConnectionStringBuilder with some key/value pairs, and then calls the Clear method and shows the results.

C#
using Microsoft.Data.SqlClient;

class Program
{
    static void Main()
    {
        SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
        builder.DataSource = "(local)";
        builder.IntegratedSecurity = true;
        builder.InitialCatalog = "AdventureWorks";
        Console.WriteLine("Initial connection string: " + builder.ConnectionString);

        builder.Clear();
        Console.WriteLine("After call to Clear, count = " + builder.Count);
        Console.WriteLine("Cleared connection string: " + builder.ConnectionString);
        Console.WriteLine();

        Console.WriteLine("Press Enter to continue.");
        Console.ReadLine();
    }
}

Remarks

The Clear method removes all key/value pairs from the SqlConnectionStringBuilder, and resets all corresponding properties. This includes setting the Count property to 0, and setting the ConnectionString property to an empty string.

Applies to

Produk Versi
SqlClient .NET Core 1.0, 1.1, 2.0, 2.1, 3.0, 3.1, 4.0, 4.1, 5.0, 5.1, 5.2
SqlClient .NET Framework 1.0, 1.1, 2.0, 2.1, 3.0, 3.1, 4.0, 4.1, 5.0, 5.1, 5.2
SqlClient .NET Standard 1.0, 1.1, 2.0, 2.1, 3.0, 3.1, 4.0, 4.1, 5.0, 5.1, 5.2