By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,932 Members | 1,474 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,932 IT Pros & Developers. It's quick & easy.

Changing the Application Domain to read correct .config file

P: n/a
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.
Jan 26 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Sridhar" wrote:
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.

Jan 26 '06 #2

P: n/a
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

"Sridhar" <Sr*****@discussions.microsoft.com> wrote in message
news:9F**********************************@microsof t.com...
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.

Jan 26 '06 #3

P: n/a
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

Jan 26 '06 #4

P: n/a
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.

"Peter Bromberg [C# MVP]" wrote:
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
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Sridhar" wrote:
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.

Jan 26 '06 #5

P: n/a
Sridhar,
Aside from Yunus' excellent suggestion, you could also consider using the
file= atttribute in your <appSettings> section. This will allow you to use an
external file containing appSettings of your choosing.

HTH,

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Sridhar" wrote:
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.

"Peter Bromberg [C# MVP]" wrote:
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
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Sridhar" wrote:
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.

Jan 27 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.