Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 510123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:04:52+00:00 2026-05-13T07:04:52+00:00

Is there a way to override a ConnectionString in an app.config. Our buildsystem runs

  • 0

Is there a way to override a ConnectionString in an app.config. Our buildsystem runs also on a server of a customer, but there the connectionString needs to be different. Because the app.config is in svn, everytime I change something in the app.config and commit it, I need to go to the server of the customer to change the connectionString back to their database…

In ant-scripts for example, this is no problem, but in an app.config I can’t seem to find a way. Tried this for example:

<connectionStrings configSource="WebConnectionString.config">
  <add name="ConnectionString"
    connectionString="..." 
    providerName="System.Data.SqlClient"/>
</connectionStrings>

What I’m trying to do is that if WebConnectionString.config exists, then use the connectionString in that config file. If it doesn’t, use the one defined in code sample (so, in app.config).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T07:04:52+00:00Added an answer on May 13, 2026 at 7:04 am

    You could do following, create a class where you encapsulate the retrieval of the connection string.

    something like this

    public static class ConnectionStringBuilder
        {
            const string ConnStringDefault = @"defaultConnString";
            static readonly string _connString = string.Empty;
            public static string Build()
            {
                return _connString;
            }
    
            /// <summary>
            /// Builds connection string from the config file with the given name
            /// </summary>
            /// <param name="name">The name.</param>
            /// <returns></returns>
            public static string Build(string name)
            {
                if (ConfigurationManager.ConnectionStrings[name] != null)
                    return ConfigurationManager.ConnectionStrings[name].ConnectionString;
    
                throw new ArgumentException("Connectionstring with given name '" + name +"' not found! ", "name");
            }
    
            /// <summary>
            /// Initializes the <see cref="ConnectionStringBuilder"/> class.
            /// </summary>
            static ConnectionStringBuilder()
            {
    
                if (ConfigurationManager.ConnectionStrings["default"] != null)
                {
                    log.Info("conn string in config found");
                    _connString = ConfigurationManager.ConnectionStrings["default"].ConnectionString;
                }
                else
                {
                    log.Info("no default connection string found, using test connection string");
                    _connString = ConnStringDefault;
                }
            }
        }
    

    and the usage would be something like this

    using(var conn = new SqlConnection(ConnectionStringBuilder.Build())
       {
          // do some stuff...
       }
    

    hope that helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to override admin templates with different files depending on Django
Is there a way to override the default 400 redirect (set in web.config) on
Is there any way to override a class method with a lambda function? For
Is there a way to override / disable a system preference pane? I'm wanting
Is there any way to override the comparison function in a F# set? I
Is there a way to override color derived from a CSS class in tag.
Is there a way to override an existing method in a partial class? Something
Is there a way to override an attribute setter on activeresource when the object
Aside from the GL Support, is there a way to override locale settings with
How can I override class attribute access in python? P.S. Is there a way

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.