Share via

connectionStrings Element (ASP.NET Settings Schema)

Specifies a collection of database connection strings, as name/value pairs, for ASP.NET applications and features.

This element is new in the .NET Framework version 2.0.

configuration Element (General Settings Schema)
  connectionStrings Element (ASP.NET Settings Schema)

<connectionStrings > 
   <add />
   <clear />
   <remove />

Attributes and Elements

The following sections describe attributes, child elements, and parent elements for this element.


None, except the attributes that are inherited by all section elements. For more information, see General Attributes Inherited by Section Elements. n ASP.NET applications, at run-time, you can assign to the ConfigSource attribute a name of an alternative configuration file. In this case, the content of the file is overwritten by the default connection string information that is contained in the Web.config file. This occurs also when the alternative file does not exist and it is created at run-time. If the Web.config does not contain any connection string information, an empty connectionStrings section is added to the alternative file.

Child Elements




Adds a connection string as a name/value pair to the collection of connection strings.


Removes all references to inherited connection strings, allowing only the connection strings that are added by the current add element.


Removes a reference to an inherited connection string from the collection of connections strings.

Parent Elements




Specifies the required root element in every configuration file that is used by the common language runtime and the .NET Framework applications.


Specifies the root element for the ASP.NET configuration settings in a configuration file and contains configuration elements that configure ASP.NET Web applications and control how the applications behave.


The connectionStrings element specifies a collection of database connection strings, as name/value pairs, for ASP.NET applications and features.

In previous versions of ASP.NET, connection strings were stored in the appSettings. In ASP.NET 2.0, features, such as Session, Membership, Personalization, and Role Manager, rely on connection strings that are stored in the connectionStrings element. You can also use the connectionStrings element to store connection strings for your own applications.

Default Configuration

Connection strings that are contained in a parent configuration file are inherited, unless the clear element is used in the child configuration file. The following default connectionStrings element is configured in the Machine.config file.

You can access the connectionStrings element programmatically. For more information, see the ConnectionStrings example.

      connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" 


The following code example demonstrates how to configure two connection strings. The first connection string can be used by an ASP.NET application and the second connection string is used by the sqlCacheDependency element, which is configured later.

<!-- Other configuration settings -->


  <add name="Sales" 
       connectionString= "server=myserver;database=Products;uid=<user name>;pwd=<secure password>" />

  <add name="NorthWind" 
       connectionString="server=.;database=NorthWind;Integrated Security=SSPI" />


  <sqlCacheDependency enabled="true" pollTime="60000">
      <add name="Northwind" />


Element Information

Configuration section handler


Configuration member





Configurable locations


Root-level Web.config

Application-level Web.config

Virtual or physical directory–level Web.config


Microsoft Internet Information Services (IIS) version 5.0, 5.1, or 6.0

The .NET Framework version 2.0

Microsoft Visual Studio 2003 or Visual Studio 2005

See Also


How to: Lock ASP.NET Configuration Settings


configuration Element (General Settings Schema)

add Element for connectionStrings (ASP.NET Settings Schema)

clear Element for connectionStrings (ASP.NET Settings Schema)

remove Element for connectionStrings (ASP.NET Settings Schema)


ASP.NET Configuration Overview

Securing ASP.NET Configuration

ASP.NET Data Access Overview

Creating the Application Services Database for SQL Server

Securing Data Access

Other Resources

ASP.NET Configuration Settings