ConfigurationManager.ConnectionStrings Property

 

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

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

static member ConnectionStrings : ConnectionStringSettingsCollection with get

Property Value

Type: System.Configuration.ConnectionStringSettingsCollection

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

Exception Condition
ConfigurationErrorsException

Could not retrieve a ConnectionStringSettingsCollection object.

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

The following example shows how to use a connection string to read data from a database.

No code example is currently available or this language may not be supported.

The previous example assumes your project has an App.config as shown below.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
    <connectionStrings>
      <add name="WingtipToys" connectionString="Data Source=(LocalDB)\v11.0;Initial Catalog=WingtipToys;Integrated Security=True;Pooling=False" />
    </connectionStrings>
</configuration>

.NET Framework
Available since 2.0
Return to top
Show: