I have a solution with multiple projects. In each project I’ve added a .config file with settings that affect the local settings.
When I tried to read the settings for the database connection, I got some values which I don’t know where they come from.
This is the .config file of DatabaseLayer Solution:
<configuration> <configSections> </configSections> <connectionStrings> <add name='localDBConnection' connectionString='Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Niko\Documents\Visual Studio 2008\Projects\GaitLinkServer\DatabaseLayer\GaitLinkDB.mdf;Integrated Security=True;User Instance=True' providerName='System.Data.SqlClient' /> </connectionStrings>
When I executed the line
private string connectionString = ConfigurationManager.ConnectionStrings['localDBConnection'].ToString();
I’ve got the null reference object exception. So I tried to execute the following command:
ConfigurationManager.ConnectionStrings[0]
and it returned
{data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true} base {System.Configuration.ConfigurationElement}: {data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true} ConnectionString: 'data source=.\\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true' Name: 'LocalSqlServer' ProviderName: 'System.Data.SqlClient'
Which don’t know where does it come from.
I would really appreciate if anyone could show how to make a global .config file for a solution with multiple projects and how to link local (Project) .config files.
Thanks!
As a note, if you use ApplicationSettings, the properties get defaults from whatever App.Config file was part of that particular project. You can specify the Application Settings in the running application, which will override the defaults.
To explain..
I have a project called CatalogData. Using the Project properties screen / Settings tab, I added a property called test, with value of test.
The Application Configuration file contains
…
…
The code generated to read the setting (make it available via My.Settings.test for VB.NET or as follows in C#
Gets defaulted in the generated code, which effectively makes the app.config file unnecessary for deployment so long as the compiled settings are OK.
In this snippet, you can see the attribute which gives the default, which is compiled.