DbConnectionStringBuilder.Remove(String) Method

Definition

Removes the entry with the specified key from the DbConnectionStringBuilder instance.

C#
public virtual bool Remove(string keyword);

Parameters

keyword
String

The key of the key/value pair to be removed from the connection string in this DbConnectionStringBuilder.

Returns

true if the key existed within the connection string and was removed; false if the key did not exist.

Exceptions

keyword is null (Nothing in Visual Basic)

Examples

C#
static void Main()
{
    DbConnectionStringBuilder builder = new
        DbConnectionStringBuilder();
    builder.ConnectionString =
        @"Provider=Microsoft.Jet.OLEDB.4.0;Data
            Source=C:\Demo.mdb;" +
        "Jet OLEDB:System Database=system.mdw;";

    // Try to remove an existing item.
    TryRemove(builder, "Provider");

    // Try to remove a nonexistent item.
    TryRemove(builder, "User ID");

    // Try to remove an existing item,
    // demonstrating that the search isn't
    // case sensitive.
    TryRemove(builder, "DATA SOURCE");
    Console.ReadLine();
}

static void TryRemove(DbConnectionStringBuilder builder, string itemToRemove)
{
    if (builder.Remove(itemToRemove))
    {
        Console.WriteLine(@"Removed '{0}'", itemToRemove);
    }
    else
    {
        Console.WriteLine(@"Unable to remove '{0}'", itemToRemove);
    }
    Console.WriteLine(builder.ConnectionString);
}

This sample displays the following output:

Removed 'Provider'
data source=C:\Demo.mdb;jet oledb:system database=system.mdw
Unable to remove 'User ID'
data source=C:\Demo.mdb;jet oledb:system database=system.mdw
Removed 'DATA SOURCE'
jet oledb:system database=system.mdw

Remarks

Because the Remove method returns a value that indicates its success, it is not required to look for the key before trying to remove the key/value pair from the DbConnectionStringBuilder instance.

Applies to

Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0

See also