简体   繁体   中英

C# My test project does not load correctly data from the web.config / app.config file of another project

My C# .NET solution includes a Web Service project and a test project. My DB connection string is set into the WS project's web.config file.

I added this web.config file as a link into the test project.

When I try to access to the connection string from the test project via:

static string pathDataBase = ConfigurationManager.ConnectionStrings["db_asnEntities"].ConnectionString;

The string was not loaded from the web.config link.

Is a test project able to load its conf from a web.config? Or does it only load it from its App.config (as it also has a test.config)? Let me know what I might have missed to have it work.

A

The configuration manager will only get values from the current project's config file. If it is a web project it uses web.config, if not it uses app.config. I've never tried reading the config from outside the project, I guess you could open it as a file with its full path but that seems like a very bad idea. I suggest you just enter the connection string in the test project config.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM