Changing the Application Domain to read correct .config file

G

Guest

Hi,

I have created a project which contains classes to read the data from the
database. This project has an App.Config file which contains the
SqlConnection String. when this code is called from a web application and if
I need to read the connection string it is reading the connection string from
the web.config of web application. I am not knowing how to change the
Application domain so that it reads the App.config file instead of Web.config
file. please let me know.

Thnx,
Sridhar.
 
G

Guest

app.config is an IDE "template" file that is used for executables (Console,
Windows Application, Windows Service). When the app is compiled the
app.config is copied into the runtime folder alongside the built exe and its
name is changed to "appName.exe.config".

app.config files are never normally used for a web application, only
web.config is.


Hope that helps.

Peter
 
Y

Yunus Emre ALPÖZEN [MVP]

Try this during start up of your application
AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE","C:\\YourCustomConfigFile.config");

this will force application to use the config file which is specified as
second parameter...

--
HTH

Thanks,
Yunus Emre ALPÖZEN
BSc, MCSD.NET
Microsoft .NET & Security MVP
 
K

KJ

Hi Sridhar,

I know we had discussed this before. But I have a new idea for you.
Create a third web project, call it WebSettingsProvider or something
like that. Add a web service to it, the purpose of which is to return
the settings required by both the web projects and the other non-web
projects in your solution. In this manner, you can store the needed
settings in one place that is accessible by all the projects (if you
don't mind adding the web references).

Aside from this type of thing, I do not know how to do what you are
asking. Maybe someone else does...

-KJ
 
G

Guest

Hi,

I am not trying to use App.Config files in a web application. Let me
explain you clearly.

I have a web application which needs to display data from a database. I
have created a project named DBMaster. This project contains a class to read
the data from database. This project is compiled into a dll. In this project,
I am using app.config(which is named is DBMaster.Config) to get the
connection string. Now I am referring this dll from my web application. When
I am calling the functions inside DBMaster and if the functions are trying to
read connection string from DBMaster.Config it is giving error. This is
because it is trying to read the connection string from Web.Config instead of
DBMaster.Config file. I hope you understood my question. Please let me know
how I could read the correct .config file.

Thanks,
Sridhar.
 

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

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top