6

This answer to another question states:


Do not forget to clear the connectionStrings first:

<connectionStrings>
   <clear />
   <add name="LocalSqlServer" connectionString="Data Source=(local);Initial Catalog=aspnetdb;Integrated Security=True" providerName="System.Data.SqlClient"/> 
</connectionStrings>

... interesting. What does that do?

Community
  • 1
  • 1
hawbsl
  • 15,313
  • 25
  • 73
  • 114

2 Answers2

6

In .Net config files are inherited, so your applications config will inherit settings from your machines config.

The <clear/> tag will remove any inherited connection strings and thereby avoids confusion and potential problems.

In ASP.Net you may have several inherited connection strings, so this is very common there.

Rune Grimstad
  • 35,612
  • 10
  • 61
  • 76
  • thanks ... might it help with this http://stackoverflow.com/q/13724682 and this http://stackoverflow.com/q/24149044? – hawbsl Jun 11 '14 at 08:35
  • It might, but probably not. Those problems seem unrelated to this, for the problem here is server-side only. – Rune Grimstad Jun 11 '14 at 09:06
2

The element removes all sections and section groups from your application that were defined earlier in the current configuration file or at a higher level in the configuration file hierarchy.

http://msdn.microsoft.com/en-us/library/aa903345(v=vs.71).aspx

so for example, if this was a child config file and the parent config file had some settings... you may not want them being inherited so you specify the clear flag to clear it and then use your settings.

Ahmed ilyas
  • 5,722
  • 8
  • 44
  • 72
  • ok, thanks so ... might it help with this http://stackoverflow.com/q/13724682 and this http://stackoverflow.com/q/24149044? – hawbsl Jun 11 '14 at 08:35
  • no. not necessarily. those are problems with not being able to connect to the database. the connection string specified to connect to would be pulled from the config file in the CODE itself. – Ahmed ilyas Jun 11 '14 at 08:37