I learn to work with the built-in profile provider of .Net, and have the following
problem:
I read that the machine.config-settings can be overridden by the web.config-settings
of a .Net-Application. The following settings in the machine.config-file are relevant
for me:
<connectionStrings> <add name="LocalSqlServer" connectionString="Data Source=(local);Initial Catalog=aspnetdb; Integrated Security=True" providerName="System.Data.SqlClient"/> </connectionStrings> <profile><providers><add name="AspNetSqlProfileProvider"connectionStringName="LocalSqlServer" applicationName="/" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/></providers></profile>
These settings work to set up local profiles.
However, when I copy the settings into the web.config of my application and change the
machine.config settings, so that they don´t work any more, I get a configuration
error.
For example, I change the name of the provider in the machine.config to “Local”.
This should be no problem, because the settings are overridden. However, when running
the application I get the error:
“The entry “AspNetSQLProvider has already been added” (my translation)
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Add a <clear /> element as the first child of <connectionStrings>. It’ll cause the configuration system to ignore all connection strings added in machine.config and use the new ones provided. You can also use <remove> element to remove a single configuration item if you don’t want to clear out the whole thing.
<connectionStrings> <clear /> <add name="LocalSqlServer" connectionString="Data Source=(local);Initial Catalog=aspnetdb;Integrated Security=True" providerName="System.Data.SqlClient"/> </connectionStrings>
The same idea applies to <providers> sections as well.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0