I have a working database application using WPF and SQL Server 2008 R2, which for two years has been getting its SQL Server connection string from the App.Config file. A few days ago on one dev machine, it started ignoring the App.Config file's connectionString, and is now using a string from somewhere else (looks like either settings.settings, or the DBML file).
Why might this be happening, and how can I get it to stop doing that?
The app.config starts out like this:
<configuration>
<configSections>
<section name="log4net" type="System.Configuration.IgnoreSectionHandler"/>
</configSections>
<connectionStrings>
<add name="DronzApp.Properties.Settings.DronzAppConnectionString"
connectionString="Server=dronz.db.123.dronzdbserver.com;Database=dronzdb;User ID=dronz;Password=secretsauce;"
providerName="System.Data.SqlClient" />
</connectionStrings>
Edit: Thanks for the suggestions from both of you for more info and where to look. I don't know where a WPF App gets the information that it ought to look in App.Config, or anyplace else, but until I learn that, here are some more pieces:
One of the first things my program does is test the database (which now fails). Right before it does that, it calls the auto-generated function InitializeComponent(), whose auto-generated code is:
/// <summary>
/// InitializeComponent
/// </summary>
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
public void InitializeComponent() {
if (_contentLoaded) {
return;
}
_contentLoaded = true;
System.Uri resourceLocater = new System.Uri("/DronzApp;component/ui/startwindow.xaml", System.UriKind.Relative);
#line 1 "..\..\..\UI\StartWindow.xaml"
System.Windows.Application.LoadComponent(this, resourceLocater);
#line default
#line hidden
}
My start window constructor calls InitializeComponent(); and then tests the database with the line:
int hmm = App.db.Dronz_FooTable.Count();
where App.db is a data context defined in the app.xaml.cs file as:
public static DronzDataDataContext db = new DronzDataDataContext();
where DronzDataDataContext is defined in auto-generated code by LINQ-to-SQL such as:
public partial class DronzDataDataContext : System.Data.Linq.DataContext ...
public DronzDataDataContext() :
base(global::DronzApp.Properties.Settings.Default.DronzConnectionString, mappingSource)
{
OnCreated();
}
Which used to heed the app.config file, and now doesn't. When I catch the DB exception (which is about a DB version problem because it is trying to use the wrong SQL server) and look at the connection string, it is asking the wrong SQL Server for a file instead of the correct connection string. The connection string it is using seems to match either the DBML file that Linq-to=SQL created when the database schema was imported, or a string in settings.settings (which is a file I don't really understand where it came from or what I'm supposed to do or not do with it).