accessing web.config from another proj in same soln

S

soni2926

hi,
i have a asp.net soln (vs 2005) which has the following 4 projects in
it
website
BusinessLayer (generates dll)
DataLayer (generates dll)
webservice

in my website project, the web.config file, i have an entry for the
datasource, as
<appSettings>
<add key="ConnString"
value="server=minebox;uid=myID;pwd=myPass;database=MyDB"/>
</appSettings>
</configuration>

when i try to access this in the website project it works fine,
getting it as:
ConfigurationManager.Appsettings["ConnString"];

but if it try the same thing in the DataLayer it returns null, is
there anyway to access it via the DataLayer? If not any suggestions
on how i can have it so the connectionstring is stored outside the
DataLayer DLL, this way the DataLayer can work with different sites
using their connectionstring entries.

I also had tried putting it in the <connectionStrings> section same
thing though, i could get to it in the website project but not outside
it.

Thanks.
 
M

Mr. Arnold

soni2926 said:
hi,
i have a asp.net soln (vs 2005) which has the following 4 projects in
it
website
BusinessLayer (generates dll)
DataLayer (generates dll)
webservice

in my website project, the web.config file, i have an entry for the
datasource, as
<appSettings>
<add key="ConnString"
value="server=minebox;uid=myID;pwd=myPass;database=MyDB"/>
</appSettings>
</configuration>

when i try to access this in the website project it works fine,
getting it as:
ConfigurationManager.Appsettings["ConnString"];

but if it try the same thing in the DataLayer it returns null, is
there anyway to access it via the DataLayer? If not any suggestions
on how i can have it so the connectionstring is stored outside the
DataLayer DLL, this way the DataLayer can work with different sites
using their connectionstring entries.

I also had tried putting it in the <connectionStrings> section same
thing though, i could get to it in the website project but not outside
it.


If the DAL resides in the virtual directory where the Web.config resides,
then you should be getting the connection string from the Web.config as the
Web.config is the root.config for the solution.

If the DAL is not in the virtual directory with the Web.config, then you
have to use an app.config and place the file where the DAL is located.

The other thing you can do as well is get the connection string from the
Web.config and pass is through the BLL down to the DAL as a string parm for
kicks and giggles, not recommended.
 
S

soni2926

hi,
the DAL is complied into a dll which the site uses, so it should be
under the same virtual directory. they are all in one soln, and i
added the dal as a reference in the website project, so i can
reference the DAL from the site's code behind. is that what you mean,
the dll being in the bin folder of the website, as that's what it is
now.
 
M

Mr. Arnold

soni2926 said:
hi,
the DAL is complied into a dll which the site uses, so it should be
under the same virtual directory. they are all in one soln, and i
added the dal as a reference in the website project, so i can
reference the DAL from the site's code behind. is that what you mean,
the dll being in the bin folder of the website, as that's what it is
now.

Yes that's what I mean. However, the Web project should have no reference to
the DAL, just the BLL, and the BLL has a reference to the DAL. I don't know
what your problem is here. But you can also use the ConfigurationManager
with a file pathing back to the folder that has the Web.config and get the
connection string that way too. Look it up use Google.
 
S

soni2926

Hi,
Thanks for the responses, I actually got it to work, problem was I was
trying to read the entry from the website's config, but then I
realized the DataAccessLayer is doing all it's work from the
webservice. The webservice was the one making the calls to the
Database via the DataAccessLayer, not the website, so I added the
connectionstring entry into the webservice's config and it worked,
thanks for the help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top