Search code examples
c#web-servicesconnection-stringapp-confignlog

App Config Connection String Not Updating For Service


I have created a webservice with an app.config which is holding my connection string. Everything works perfectly and as expected, apart from that when I change the connectionstring to point to a new table the service will continue to point at the old address (even when I switch the service off).

The only way I have found around this so far is to rebuild the solution.

Can anyone think why the connectionstring only updates when I rebuild?

()

    private const string ConnectionStringName = "ConnectionString";
    private readonly string _connectionString;
    private readonly Logger _logger;

    public AX2012DataPassing()
    {
#if DEBUG
        Thread.Sleep(10000);
#endif
        InitializeComponent();
        _logger = LogManager.GetCurrentClassLogger();             
        _logger.Info("Attempting to initialize connection string" + ConnectionStringName);

        try
        {
            _connectionString = ConfigurationManager.ConnectionStrings[ConnectionStringName].ConnectionString;
            //// Test connection established, will throw error if does not
            GetConfigValue(string.Empty);
            _logger.Info("Connection String " + ConnectionStringName + " initialized");
        }
        catch (Exception e)
        {
            _logger.Info("Connection String " + ConnectionStringName + " failed to initialize");
            _logger.Fatal("Connection String " + ConnectionStringName + " failed to initialize:" + e.Message);
            return;
        }

Solution

  • Try an IIS reset as the connection string may be cached.