Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

app.config in DAL and web.config in WebApplication

I'm writing an application using Entity Framework and ASP.NET MVC, so I decided to separate DAL from MVC Web Application. And actually everything fine except next problem (if it's problem): I had to copy Entity connection string from app.config of DAL project to Web.config of Web Application. And actually it's look correct: DAL should not to know about connection string to Data, it's duty of Main Application.

But I really don't like, that I have to keep Entity connection string in app.config of DAL, because it's need to update my EntityModel (*.edmx). Is there some best practice to reference to connection string of Web Application? Or shoul I just leave it like it is now?

like image 618
Danil Sabirov Avatar asked Nov 12 '12 15:11

Danil Sabirov


People also ask

Is app config and Web config are same?

The web. config file is required for ASP.NET webpages. The app. config file is optional in an application and doesn't have to be used when writing desktop applications.

What is app config and Web config?

Web. Config is used for asp.net web projects / web services. App.Config is used for Windows Forms, Windows Services, Console Apps and WPF applications.

What is app config?

App. Config is an XML file that is used as a configuration file for your application. In other words, you store inside it any setting that you may want to change without having to change code (and recompiling). It is often used to store connection strings.

What is configuration in Web config?

web. config file is an XML-based configuration file used in ASP. NET-based applications to manage various settings that are concerned with the configuration of our website. In this way, we can separate our application logic from configuration logic.


1 Answers

So, just an an explanation of what is occurring here. When you are developing your application, the DAL project is, by nature, it's own project. When editing the DAL project, Visual Studio will use the values in the projects configuration file. Thus, why the connection string staying in that app.config file.

Now, when you publish your entire solution to a web server, the web application is the actual application that is running. This has a reference to the DAL dll that was complied during the build process. Given this, the DAL dll will get all of its configuration values from the web.config as this is the configuration file for the primary executing assembly.

To answer your question, its probably best to keep them in both the app.config and web.config for no other reason than you will not have to 'create a new connection' each time you need to update your model. The DAL project, as far as I know, will not ever look to another projects configuration file while in Visual Studio. However, having connection strings in both the app.config and web.conig will not impact your deployment. The web.config settings will always be used.

like image 58
Tommy Avatar answered Sep 27 '22 23:09

Tommy