1

Could you help me understand what this piece of code does in simple English? This is a beginner. Thank you in advance.

<connectionStrings>
<add name="BalloonShopConnection" connectionString="Server=(local)\Sql➥
Express; Database=BalloonShop; User=balloonshop; Password=ecommerce" ➥
providerName="System.Data.SqlClient" />
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer" connectionString="Server=(local)\SqlExpress;➥
Database=BalloonShop; User=balloonshop; Password=ecommerce" providerName=➥
"System.Data.SqlClient" />
</connectionStrings>

This is from a tutorial. I covered everything up to first half of the book but this seems strange.

Anna T
  • 1,027
  • 7
  • 21
  • 29
  • 1
    What part seems strange to you? – Mark M Jun 08 '12 at 19:42
  • 1
    A little research is required on your part. Here's a good place to start: [ConnectionSTringsSettings Class](http://msdn.microsoft.com/en-us/library/system.configuration.connectionstringsettings) – Jeremy Jun 08 '12 at 19:42

2 Answers2

2

The web.config for your app is only part of the configuration settings your app gets. The total configuration is a combination of your web.config as well as the machine.config file, and settings defined in IIS. This line:

<remove name="LocalSqlServer"/>

implies that the there is a connection string named LocalSqlServer defined elsewhere that you may be getting from somewhere other than your web.config. So in your web.config they are explicitly removing that other LocalSqlServer connection string you would otherwise get, and replacing it with the one defined below that line. That change only affects your application. This is explained here: http://weblogs.asp.net/jgalloway/archive/2012/01/17/10-things-asp-net-developers-should-know-about-web-config-inheritance-and-overrides.aspx

If the remove tag wasn't there, and that connection string was also defined higher up the chain, your app would use the one defined higher up, and ignore the one defined in your web.config (which can be quite confusing!). That's why the remove tag is needed.

See also: Avoid web.config inheritance in child web application using inheritInChildApplications

Community
  • 1
  • 1
  • hatchet: Indeed, especially the "remove" part I didn't understand. Your explanation is in plain English, very helpful and targeted to the user-level I specified. Thanks a lot! – Anna T Jun 08 '12 at 22:53
1

You add connection string which names BalloonShopConnection. Your sql server names (local)\SqlExpress; Your databese is BalloonShop user is balloonshop so you add second one which is very similar :)

Mateusz Rogulski
  • 7,357
  • 7
  • 44
  • 62