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 489479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T01:48:44+00:00 2026-05-13T01:48:44+00:00

I have a MVC web site that worked well, until I moved it into

  • 0

I have a MVC web site that worked well, until I moved it into test, where it fell over. After some investigation If found that because I had split the ‘model’ into its own seperate project, the model was using the connectionstring from its own app.config (not the web.config of the website).

So I found an article somewhere (can’t find the link now), showing how I can use the web.config instead – great, I got the site into test.

Unfortuanatly, the next time I tried to get the site implemented in test again, I got the same problem, and after a while discovered that somehow the app.config of my model had re-written the connection string DOH!

What is the best practice here? I need the database configuration to be in a file that is easily changed by my system administrators

  • 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-13T01:48:45+00:00Added an answer on May 13, 2026 at 1:48 am

    If your project has both an App.config and a Web.config file then you’ll want to tie them together so they share the connection string. Doing so is easy. In the *.config files add the line:

    <connectionStrings configSource="WebCS.config" />
    

    The webcs.config will look like:

    <connectionStrings>
     <add name="YourConnString" connectionString="Data Source=Server;Initial Catalog=YourDB;User ID=SQLID;Password=Password" providerName="System.Data.SqlClient"/>
    </connectionStrings>
    

    This will permit you to reference the same connection string from multiple places and make it easy to have connection strings that differ on your dev, test and deployment servers.

    Update: If you are doing TDD or are otherwise separating out your logic into a separate DLL you may have both types of .Config files and thus the issue that you raise. Of course, a separate Business Logic DLL is a “best practice” for creating forms-based Web apps in ASP.NET. For example, I place only UI code in the web site itself and then call into a DLL for all business-related and data handling logic. This not only helps with a separation of concerns but it makes testing easy as well.

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

Sidebar

Related Questions

I have a asp.net-mvc web site that i took over and there is a
I have a mvc web site that contains one non-mvc page (it is using
I have an iPad app that submits orders to an ASP.NET MVC web site
This is regarding ASP.NET MVC. Let's say I have a web site that is
I have an ASP.NET MVC 3 web site that uses Windows Authentication running under
I have an ASP MVC 3 site that allows a user to submit some
I have an ASP:NET MVC 2 web site that is on SSL. I want
I have some static content on my web site that I have set up
I have an ASP.NET MVC web site. I have many actions which require authentication
I have a web site (ASP.NET, no MVC) with multiple web forms for filling

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.