asp.net.ph

Skip Navigation Links

<connectionStrings> Section

ASP.NET Syntax   ASP.NET Configuration Sections


.NET Framework version 2.0

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

<connectionStrings >

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

</connectionStrings>

Attributes and Elements

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

Attributes

None, except the attributes that are inherited by all section elements.

Child Elements


Element Description
add Adds a connection string as a name/value pair to the collection of connection strings.
clear Removes all references to inherited connection strings, allowing only the the connection strings that are added by the current add element.
remove Removes a reference to an inherited connection string from the collection of connections strings.

Parent Elements


Element Description
configuration Specifies the required root element in every configuration file that is used by the common language runtime and the .NET Framework applications.
system.web 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.

Remarks

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.

<connectionStrings>
   <add name = "LocalSqlServer"
      connectionString = "data source=.\SQLEXPRESS;Integrated Security=SSPI;
         AttachDBFilename= | DataDirectory | aspnetdb.mdf;User Instance=true"
      providerName = "System.Data.SqlClient" />

</connectionStrings>

Example

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.

<configuration>
   <!-- Other configuration settings -->

   <connectionStrings>
      <add name = "Sales"
         providerName = "System.Data.SqlClient"
         connectionString= "server=myserver;database=Products;uid=salesUser;pwd=sellMoreProducts" />
      <add name = "NorthWind"
         providerName = "System.Data.SqlClient"
         connectionString = "server=.;database=NorthWind;Integrated Security=SSPI" />
   </connectionStrings>

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

</configuration>
See Also

ASP.NET Configuration   ConnectionStringsSection Class   ConnectionStringSettings Class   ConnectionStringSettingsCollection Class



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note