Jeremy Jeremy - 1 month ago 4
ASP.NET (C#) Question

Why do we have to put the connection string in app.config?

i just started my first mvc4 solution. i have created 2 projects. the first is an MVC4 project and it contains all the controllers (it is the web app) and the second is only for Models, classes and Entity Framework data access.

i would like to know why do i need to put the connection string in app.config (in data access) as long as the same connection string is in the web.config?

i am worried about the debug and release configuration because till now i am only capable of transforming the connection string in web.config but not in app.config? i don't want to publish settings and start making tests on a production environment because of that connection string in app.config.

hope my question is clear!

Answer

You don't need to put it in app.config. In fact, app.config doesn't do anything in Class Library projects.

You should only put it in the config file for your actual app (Web.config for web, or app.config for EXEs).