ConfigurationManager.ConnectionStrings Property

Note: This property is new in the .NET Framework version 2.0.

Gets the ConnectionStringsSection data for the current application's default configuration.

Namespace: System.Configuration
Assembly: System.Configuration (in system.configuration.dll)

public static ConnectionStringSettingsCollection ConnectionStrings { get; 
/** @property */
public static ConnectionStringSettingsCollection get_ConnectionStrings ()

public static function get ConnectionStrings () : ConnectionStringSettingsCollection

Property Value

Returns a ConnectionStringSettingsCollection object containing the contents of the ConnectionStringsSection object for the current application's default configuration.

Exception typeCondition


Could not retrieve a ConnectionStringSettingsCollection object.

A ConnectionStringsSection object contains the contents of the configuration file's connectionStrings section.

The following code example shows how to get a named connection string using the ConnectionStrings property.

// Get connectionStrings.
static void GetConnectionStrings()
    // Get the connectionStrings.
    ConnectionStringSettingsCollection connectionStrings =

    // Get the collection enumerator.
    IEnumerator connectionStringsEnum =

    // Loop through the collection and 
    // display the connectionStrings key, value pairs.
    int i = 0;
    Console.WriteLine("Connection strings.");
    while (connectionStringsEnum.MoveNext())
        string name = connectionStrings[i].Name;
        Console.WriteLine("Name: {0 Value: {1",
        name, connectionStrings[name]);
        i += 1;

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions