471,578 Members | 1,491 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Changing the Application Domain to read correct .config file

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
5 2169
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
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
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
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
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.

Similar topics

5 posts views Thread by Martin Robins | last post: by
21 posts views Thread by Chris | last post: by
8 posts views Thread by Vishwanathan Raman | last post: by
2 posts views Thread by Matthew Hood | last post: by
4 posts views Thread by Srini | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by Vinnie | last post: by
1 post views Thread by lumer26 | last post: by
reply views Thread by lumer26 | last post: by

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.