In this example, you will learn how to write a connection string in Web.Config, Writing a connection string in Web.Config makes you easy to change the database name, server name, username and password of database login. Doing this, you don't need to change a connection string setting in all pages if your Web project has a large number of pages.
Here's an example
<connectionStrings>
<!--Attach a database file which is placed inside the data directory of Web Application-->
<add name="ConnectionString_1"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;
User Instance=true" providerName="System.Data.SqlClient"/>
<!--Attach a database file which is placed inside the data directory of Web Application-->
<add name="ConnectionString_2"
connectionString="Data Source=[SERVER_NAME];AttachDbFilename=[DATABASE_NAME AND PATH e.g c:\app_data\aspxtutorial.mdf];
Integrated Security=True;Connect Timeout=30;User Instance=True" providerName="System.Data.SqlClient"/>
<!--Relative path of database in side connection string-->
<add name="ConnectionString_3"
connectionString="server=[SERVER_NAME];database=[DATABASE_NAME];uid=[USER ID];password=[PASSWORD];
Connect Timeout=20; Max Pool Size=2000 " />
</connectionStrings>