Reputation: 145
I have a console application in which website project is added as dll. Inside dll ConfigurationManager.ConnectionStrings["XXX"]
is called which is always returning null
.
But web.config in dll has connectionstring named 'XXX'. Can any one suggest what is going wrong?
Upvotes: 1
Views: 7090
Reputation: 69
I had a slightly different problem that I haven't seen an answer to. I was using.
ConfigurationManager.ConnectionStrings["XXXX"].ConnectionString;
When I opened up web.config I saw that the connection string I had created was prefixed with "WebApplicationAPI.Properties.Settings." - putting the entire string in worked for me:
ConfigurationManager.ConnectionStrings["WebApplicationAPI.Properties.Settings.XXXX"].ConnectionString;
Upvotes: 1
Reputation: 6712
web.config is for web application.
For console application you have to use app.config.
Well, actually that's the default configuration for C#, I won't be surprised some advanced user could make it go the other way arround.
Upvotes: 0
Reputation: 8471
Your config file is not in the .dll. So you're referencing nothing I would suspect! Unless you've manually copied the web.config file to the correct location or references it via an absolute path?
Upvotes: 0
Reputation: 6577
Try copying the config file to your console project. Or at least the connection strings section. Probably in an App.config.
Upvotes: 2
Reputation: 6105
I don't think .config file of the .dll is added to your console project together with the dll. You need to have the .config in your executing project.
Upvotes: 3