0

I have a ASP.NET MVC 4 web project

WebUI

that references a ASP.NET 4 Code Library

DAL

The Code Library has a reference to the SlowCheetah 2.5.5 NuGet package and is setup with several transformations for it's App.Config.

The WebUI is using the normal Web.Config transformations but I have also added a reference to SlowCheetah as a test for my problem but it didn't change my issue.

When I publish using

MS Web Deploy

in Visual Studio 2012 or when I publish straight to

File System

using a QA configuration the correct Web.QA.config is put in the root of my website, however the referenced class library configuration is not working, I get a sql connection error on the home page which alerts me that the correct App.Config transformation is most likely not being used for the referenced DAL project.

I thought this would be a .dll.config file in the bin folder for the WebUI, but I am not too sure as I have this working on another web server where I manually changed the default App.Config and Web.Config files and there is no .dll.config file present in the root bin directory of the website.

Anyone know how to get this working?

UPDATE:

Examples below:

DAL Code Library project App.Config

<configuration>
    <configSections>
 </configSections>
    <connectionStrings>
  <add name="DAL.Properties.Settings.DefaultConnection" connectionString="Data Source=(local);Initial Catalog=MyDB;Integrated Security=True;" />
 </connectionStrings>
</configuration>

Part of Web.Config from my WebUI project

  <connectionStrings>
    <add name="WebUI.Properties.Settings.DefaultConnection" connectionString="Data Source=(local);Initial Catalog=MyDB;Integrated Security=True;" />
  </connectionStrings>

I use a Settings.settings file for each project.

How can I merge the App.Config connection into my Web.Config so that it is transformed during publishing? preferably I would want it to just use the one connection when publishing to the web.

At the moment the DAL referenced project works on the web application if I set the app.config correctly (which only makes some sense to me since its a referenced .dll).

Does adding this DAL.Properties.Settings.DefaultConnection connection to my web.config replace the one the DAL is using?

Pricey
  • 5,799
  • 12
  • 60
  • 84

1 Answers1

1

All of your settings for the web application will come from the web.config file - the app.config won't be used or deployed with the web app. Most likely, that config is there because you are using Entity Framework and that's where the EDMX functionality stores it's connection string. If you put the connection string in the web.config (and use the appropriate config transformations), you should be good.

M Smearer
  • 361
  • 2
  • 5
  • I am using Dapper in my DAL project. The database connection that is in my App.Config is used within this DAL project, as part of a repository... it is only used when the WebUI doesn't supply my repo with an existing connection to make a database request. The connections both have different names, if this app.config wasn't needed then shouldn't the publishing work? I know it works when I manually set the default Web.Config and App.Config to the required connection, but I want the publishing to select the correct config file. – Pricey Jun 03 '13 at 16:15
  • To add to this, the DAL doesn't know about the WebUI, and isn't going to have access to the relevant connection string in the config. – Pricey Jun 03 '13 at 20:02
  • Typically, you have one .config per application boundary. If it's an .exe, you've got an app.config. If it's a web app, you've got a web.config. Just one. When you fire up ConfigurationManager in code, it will use the .config associated with the application, not some component. – M Smearer Jun 03 '13 at 23:12
  • Another way to put this - the app.config associated with your DAL is meaningless at runtime - it won't be used in any manner whatsoever unless you write some very odd, non-standard code to do so. ALL config settings for your web application should be in the web.config. – M Smearer Jun 03 '13 at 23:14
  • so are you saying it needs merging into the web.config and also more importantly now my DAL has to have a reference to my WebUI? which I don't see that it needs to know anything about the UI. – Pricey Jun 03 '13 at 23:54
  • 1
    I'm saying the settings that your DAL consumes will be in the web.config. No reference is needed. Check out the answer [here](http://stackoverflow.com/questions/1491858/accessing-a-web-config-file-in-a-third-party-library) – M Smearer Jun 04 '13 at 16:26
  • Ok thanks. I think my confusion came into it because my solution has the referenced project inside of it, and for some crazy reason I felt that when I published my WebUI it would know to use the correct connection in the referenced project. What also confuses me is how this works by setting the app.config file correctly, even though the connection my reference project needs is not inside my web.config – Pricey Jun 04 '13 at 16:50
  • Please take a look at my update to my question because your link just confirmed that I have to put the `DAL` connection into my `Web.Config`, but I am not entirely sure how I should handle that and if it can be done automatically based on the `App.Config` in the `DAL` project. – Pricey Jun 04 '13 at 17:00
  • I fixed it by switching to using configuration manager and removing the app.config stuff from my DAL. – Pricey Jun 11 '13 at 12:01