views:

12

answers:

1

I want to make a Front Office, Back Office and a Windows Service to take the Connection String from one place.

I tried to use System.Configuration.ConfigurationManager.ConnectionStrings["SqlServerDatabase"].ConnectionString; but this works only for websites, the connection string is take from web.config

For Windows Service, I tried System.Configuration.ConfigurationManager.AppSettings["SqlServerDatabase"] but this will look in app.config, and didn't worked for me

namespace DAL
{
    public class DataBase
    {
        public static string ConnectionString
        {
            get
            {
                // return connection string
            }
        }
....

All 3 applications share the same database access layer called DAL.
It is important to have the Connection String in one place and also to be configurable (not requiring code recompilation)

+1  A: 

You could put the connection string in the machine.config of the server. This way all the application may use it. Another advantage of this method is that you won't need to change connection strings when switching between environments. Just store it at the machine level.

Darin Dimitrov
is there a machine.config for localhost ?
pixel3cs