accessing web.config from another proj in same soln

  • Thread starter Thread starter soni2926
  • Start date Start date
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.
 
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.
 
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.
 
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.
 
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.
 
Back
Top