Asp.NET - how to make sure web.config is used for conectionstring (not app.config)

I have an MVC website that worked well until I moved it to the test where it crashed. After some research, if it was found that since I split the “model” into my own separate project, the model used the connection string from its own app.config (and not the web.config site).

So, I found the article somewhere (I can’t find the link now), showing how I can use web.config instead - fine, I got the site in test mode.

Unfortunately, the next time I tried to start the site again in the test, I had the same problem, and after a while I found that somehow the app.config of my model rewrote the DOH connection string!

What is the best practice here? I need to set up a database in a file that my system administrators can easily modify.

+3
source share
3 answers

If your project has an App.config file and a Web.config file, you will want to link them together so that they share the connection string. It is easy to do. In the * .config files add the line:

<connectionStrings configSource="WebCS.config" />

Webcs.config will look like this:

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

This will allow you to reference a single connection string from multiple locations and simplify connecting connection strings that vary on development, testing, and deployment servers.

. TDD DLL, .Config , , , . , DLL Business Logic - " " - ASP.NET. , -, DLL - . , .

+1

ASP.NET app.config, .

+2

Source: https://habr.com/ru/post/1725317/


All Articles