asp.net.ph

Skip Navigation Links

<connectionStrings> add Element

ASP.NET Syntax   ASP.NET Configuration Sections


.NET Framework version 2.0

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

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

<add name = "connection string name"
   connectionString = "connection string"
   providerName = "ADO.NET data provider" />

Attributes and Elements

The following sections describe attributes, child elements, and parent elements.

Attributes


Attribute Description
connectionString Required String attribute.

Defines the connection string value. The value can be an empty string ( "" ). No checking is done to verify its validity.

The default is an empty string ( "" ).

name Required String attribute.

Defines the key to use to access the connection string value. This attribute overrides any inherited key with the same name.

The default is an empty string ( "" ).

providerName Optional String attribute.

The name of the ADO.NET provider to use to access the underlying data store.

The default is "System.Data.SqlClient".

Inherited attributes Optional attributes.

Attributes inherited by all section elements.

For more information, see Shared Configuration Attributes.


Child Elements

None.

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.
connectionStrings Specifies a collection of database connection strings ( as name/value pairs ) for ASP.NET applications and ASP.NET features.

Remarks

The add element adds a connection string as a name/value pair to the collection of connection strings in the connectionStrings element.

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

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 element 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 a connection string for an application that uses the Northwind database.

<configuration>
   <connectionStrings>
      <add name = "Northwind" connectionString = 
            "Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind;"
         providerName = "System.Data.SqlClient" />
   </connectionStrings>
</configuration>
See Also

<connectionStrings> Section   <connectionStrings> clear Element   <connectionStrings> remove Element



© 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