473,396 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Access to a web.config from another project

I have a Solution that contains a website and its web.config and
another project named testWebSite.
I need to access to the web.*config located in the website project
from testWebSite like this:
string dbCs =
ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
This code failed and generates an exception because (it seems) that
the web.config is available only in the folder where it is.

So what is the solution for Access to a web.config from another
project ?

Sam

Dec 19 '07 #1
3 2882
extract the setting u need to access to separate config file and refer to
this file from both web.configs

--
WBR, Michael Nemtsev [.NET/C# MVP].
Blog: http://spaces.live.com/laflour

"sk*****@gmail.com" wrote:
I have a Solution that contains a website and its web.config and
another project named testWebSite.
I need to access to the web.*config located in the website project
from testWebSite like this:
string dbCs =
ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
This code failed and generates an exception because (it seems) that
the web.config is available only in the folder where it is.

So what is the solution for Access to a web.config from another
project ?

Sam

Dec 19 '07 #2
I need to add some precision:
The second project is not a webSite but a Library (dll) for testing).

Sam
Dec 20 '07 #3
In that case you'd do the following 3 lines:

string pathToConfigFile = "c:\mydllprojectfolder\mydll.config";

system.configuration.configuration oConfig =
system.configuration.configurationManager.OpenExeC onfiguration(pathToConfigFile) as system.configuration.configuration;

string dbCs =
oConfig.connectionStrings.connectionStrings.item["myConnectionString"].connectionString;

Again I'd like to urge you to reconsider the reason you're having to do
this. If you're doing this to get a dev database connection string or other
dev environment information you're doing too much work for something that
could be done within the website's config file in much less effort.

Let me know if this helps. Thanks,

--
Mohamad Elarabi
Lead Developer. MCTS, MCPD.
"sk*****@gmail.com" wrote:
I need to add some precision:
The second project is not a webSite but a Library (dll) for testing).

Sam
Dec 20 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Craig | last post by:
I've developed an single sign on web application that we'd like to use with all the applications we're developing. The application's connection string is stored in web.config. I've gotten some...
4
by: RM | last post by:
Had VS .Net 2002 installed on W2k Server SP3 and supported a number of web sites. Installed VS .Net 2003 on Friday and now all web sites using .Net & MS ACCESS get this strange error upon open. ...
6
by: Ruslan | last post by:
Hello, I have to project: one ASN.NET project and another - Web Service in the same solution. I want to use the same web.config and global.asax files. Does it possible?
4
by: Big Dave | last post by:
Good morning. I have a solution set up with multiple projects. One is a web project and it contains my web.config file. I would like to build a class within another project (a class library)...
1
by: Jody Gelowitz | last post by:
We are having an issue in that when trying to read a file that is on Server2 from Server1 (through our ASP.NET project), we receive the error: Access to the path "\\Server2\MyShare\MyFile.tif" is...
3
by: daokfella | last post by:
In my solution, I have a project that is my data access layer. This layer simply consists of strongly-typed datasets created by dragging tables from the server explorer into the dataset designer....
7
by: Tony K | last post by:
How can I customize, at runtime, the path for the OLEDB connection uses. I used the Add Data Source Wizard and found the path set by the wizard is ReadOnly.
2
by: bz | last post by:
Hi, I have a library project that implements a Business Layer for a web and a desktop application All my business classes are in this lib, so I have here the connection string to database as...
3
by: Jeff | last post by:
I have a solution with two projects. Project A is the startup project, while Project B serves as the project with the data logic. At run time, the first thing I need to do is write to Project...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.