OleDbConnectionStringBuilder.Keys Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets an ICollection that contains the keys in the OleDbConnectionStringBuilder.

Namespace:   System.Data.OleDb
Assembly:  System.Data (in System.Data.dll)

public override ICollection Keys { get; }

Property Value

Type: System.Collections.ICollection

An ICollection that contains the keys in the OleDbConnectionStringBuilder.

The order of the values in the ICollection is unspecified, but it is the same order as the associated values in the ICollection returned by the Values property.

The following console application example creates a new OleDbConnectionStringBuilder. The code loops through the ICollection returned by the Keys property displaying the key/value pairs.


This example includes a password to demonstrate how OleDbConnectionStringBuilder works with connection strings. 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.

using System.Data.OleDb;

class Program
    static void Main()
            // Build an empty instance, just to see
            // the contents of the keys.

            // Create a SQL Server connection string.
            DumpBuilderContents("Provider=sqloledb;Data Source=(local);" +
                "Initial Catalog=AdventureWorks;" +
                "User Id=ab;Password=Password@1");

            // Create an Access connection string.
            DumpBuilderContents("Provider=Microsoft.Jet.OLEDB.4.0;" +
                @"Data Source=C:\Sample.mdb");

            // Create an Oracle connection string.
            DumpBuilderContents("Provider=msdaora;Data Source=SomeOracleDb;" +
                "User Id=userName;Password=Pass@word1;");

            // Create a Sybase connection string.
            DumpBuilderContents("Provider=ASAProv;Data source=myASA");

            Console.WriteLine("Press any key to finish.");

        catch (System.ArgumentException ex)

            Console.WriteLine("Error: " + ex.Message);

    private static void DumpBuilderContents(string connectString)
        OleDbConnectionStringBuilder builder =
            new OleDbConnectionStringBuilder(connectString);
        Console.WriteLine("Original connectString   = " + connectString);
        Console.WriteLine("builder.ConnectionString = " + builder.ConnectionString);
        foreach (string key in builder.Keys)
            Console.WriteLine(key + "=" + builder[key].ToString());

.NET Framework
Available since 2.0
Return to top