views:

2267

answers:

2

How can one specify the connection string in a config file of a class library and later modify this when used in a ASP.NET Web Application?

The Class library is a data access layer that has a Dataset connecting to a database based on a connection string specified in a config file (Settings.settings/app.config).

This class library is used in a web application where user inputs data and is written to the database using the DAL classes & methods exposed in the class library.

Now, I want to migrate this application from development environment to testing environment and later to production. The problem I'm facing is that after migrating to testing, the app in testing still connects to development database. I've changed the connection string mentioned in <class library>.dll.config file but this seems to have no impact.

Can someone explain the right way to achieve this? Thanks in advance for any help. Cheers.

+2  A: 

With the .config files the name has to match the main executing assembly. For example I had a situation like yours, I needed a class library to have its settings in a .dll.config file. While it was able to reference it the actual application would not be able to read the config file because it was expecting .exe.config. Renaming the .dll.config to .exe.config fixed the problem.

In your case migrating your connection strings from .dll.config to web.config should fix your problem!

Good luck!

Joshua
Thank you Joshua, it worked!
Nahom Tijnam
A: 

I have a similar issue.. but its a web app that the DAL is included in, and in this case there is no app.config, its a web.config file... Any ideas?

@David - I'm not sure if I understood your situation correctly, but if it is that the DAL was created in a class library project which you want to use web app, then put the connection string in the web.config file and this should be available to the DAL dlls that you include in your web application.
Nahom Tijnam