Redigera

Dela via


SqlConnectionStringBuilder.Clear Method

Definition

Clears the contents of the SqlConnectionStringBuilder instance.

public:
 override void Clear();
public override void Clear ();
override this.Clear : unit -> unit
Public Overrides Sub 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.

using System.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();
    }
}
Imports System.Data.SqlClient
    
Module Module1
    Sub Main()
        Dim builder As 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()
    End Sub
End Module

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

See also