473,394 Members | 1,887 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,394 software developers and data experts.

Where to place app.config file

Hello,

I have the following scenario: I have a solution with 4 projects
Project1 = MainWindow (Windows EXE)
Project2 = PresentationLayer (DLL)
Project3 = BusinessLayer (DLL)
Project4 = DataLayer (DLL)

I have referenced all of the other projects in the first project so that
I could use the objects I've created in them. However, I am running in
to the following situation. In the DataLayer Project, I have created a
class called Database. This database class has a static method called
Connection which retruns a SqlConnection object.

I have created an app.config file for the data layer project and have
added the key called "SqlConnection" for my sql server, here is an exmple:

<appSettings>
<add key="SqlConnection" ...>
</appSettings>

In the DataLayer Static method, I am calling the following:
public static SqlConnection Connection()
{
string sqlConnection = ConfigurationSettings.AppSettings["SqlConnection"];

//creating of sql connection object
SqlConnection connection = new SqlConnection(sqlConnection);

return(connection)
}

However, when I call this in my code, I get an error stating that the
connection string has not been initialized. One thing I've noticed is
that I've gone to Project1's debug folder (where all of the aseemblies
are) and I notice that the app.config file for the data layer project is
not there.

I am trying to avoid to create the app.config file for Project1 and
passising it's connection string from there. can anyone tell me what I
can do to have this work the way I want it to work?

Any advice or tips will be greatly appreciated.
Nov 16 '05 #1
4 2792
app.config is for the .exe not for the dll frameworks. You should pass the
connection string into your Database class in its contructor. Then your
main app loads the app.config, gets the connection info and passes it to the
DataLayer. The point here is that by doing it this way you allow your
DataLayer to be re-used by other apps that pass in different connection
strings.

JIM

"Ed_P." <ed**@no-mail.com> wrote in message
news:Ok**************@tk2msftngp13.phx.gbl...
Hello,

I have the following scenario: I have a solution with 4 projects
Project1 = MainWindow (Windows EXE)
Project2 = PresentationLayer (DLL)
Project3 = BusinessLayer (DLL)
Project4 = DataLayer (DLL)

I have referenced all of the other projects in the first project so that I
could use the objects I've created in them. However, I am running in to
the following situation. In the DataLayer Project, I have created a class
called Database. This database class has a static method called
Connection which retruns a SqlConnection object.

I have created an app.config file for the data layer project and have
added the key called "SqlConnection" for my sql server, here is an exmple:

<appSettings>
<add key="SqlConnection" ...>
</appSettings>

In the DataLayer Static method, I am calling the following:
public static SqlConnection Connection()
{
string sqlConnection = ConfigurationSettings.AppSettings["SqlConnection"];

//creating of sql connection object
SqlConnection connection = new SqlConnection(sqlConnection);

return(connection)
}

However, when I call this in my code, I get an error stating that the
connection string has not been initialized. One thing I've noticed is
that I've gone to Project1's debug folder (where all of the aseemblies
are) and I notice that the app.config file for the data layer project is
not there.

I am trying to avoid to create the app.config file for Project1 and
passising it's connection string from there. can anyone tell me what I
can do to have this work the way I want it to work?

Any advice or tips will be greatly appreciated.

Nov 16 '05 #2
If you create the app.config for project1 your DLL will just read that APP
config. Class libraries read the app.configs of the process they are loaded
into. So there would be no need to pass the connection string from the EXE
to the DLL. I believe this was done because you may actually use that DLL
with multiple EXE's.

I saw something on one of the group that showed how to get the DLL to read
from a different config, you may try searching groups.google.com if you
don't like the idea of using one App.config.

--
Thanks
Wayne Sepega
Jacksonville, Fl
"When a man sits with a pretty girl for an hour, it seems like a minute. But
let him sit on a hot stove for a minute and it's longer than any hour.
That's relativity." - Albert Einstein

"Ed_P." <ed**@no-mail.com> wrote in message
news:Ok**************@tk2msftngp13.phx.gbl...
Hello,

I have the following scenario: I have a solution with 4 projects
Project1 = MainWindow (Windows EXE)
Project2 = PresentationLayer (DLL)
Project3 = BusinessLayer (DLL)
Project4 = DataLayer (DLL)

I have referenced all of the other projects in the first project so that
I could use the objects I've created in them. However, I am running in
to the following situation. In the DataLayer Project, I have created a
class called Database. This database class has a static method called
Connection which retruns a SqlConnection object.

I have created an app.config file for the data layer project and have
added the key called "SqlConnection" for my sql server, here is an exmple:

<appSettings>
<add key="SqlConnection" ...>
</appSettings>

In the DataLayer Static method, I am calling the following:
public static SqlConnection Connection()
{
string sqlConnection = ConfigurationSettings.AppSettings["SqlConnection"];

//creating of sql connection object
SqlConnection connection = new SqlConnection(sqlConnection);

return(connection)
}

However, when I call this in my code, I get an error stating that the
connection string has not been initialized. One thing I've noticed is
that I've gone to Project1's debug folder (where all of the aseemblies
are) and I notice that the app.config file for the data layer project is
not there.

I am trying to avoid to create the app.config file for Project1 and
passising it's connection string from there. can anyone tell me what I
can do to have this work the way I want it to work?

Any advice or tips will be greatly appreciated.

Nov 16 '05 #3
Ed,

You should not have an individual application configuration file for
your dll. Basically, the app config file is meant to be the configuration
for the application as a whole, which your component is a part of. Because
of this, you will have to have an application configuration file for the
entry point for the CLR (in this case, your main executable).

If you want to have a configuration file for your assembly, you are
going to have to code it up yourself, but I would recommend against it, as
it doesn't make much sense (why have multiple areas where the dll can be
configured from an application standpoint).

If the services offered by your assembly are truly so universal, and
require it's own configuration, then you should consider making it a
service, as that is more in line with what it is providing, as well as the
needs it has for configuration.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ed_P." <ed**@no-mail.com> wrote in message
news:Ok**************@tk2msftngp13.phx.gbl...
Hello,

I have the following scenario: I have a solution with 4 projects
Project1 = MainWindow (Windows EXE)
Project2 = PresentationLayer (DLL)
Project3 = BusinessLayer (DLL)
Project4 = DataLayer (DLL)

I have referenced all of the other projects in the first project so that I
could use the objects I've created in them. However, I am running in to
the following situation. In the DataLayer Project, I have created a class
called Database. This database class has a static method called
Connection which retruns a SqlConnection object.

I have created an app.config file for the data layer project and have
added the key called "SqlConnection" for my sql server, here is an exmple:

<appSettings>
<add key="SqlConnection" ...>
</appSettings>

In the DataLayer Static method, I am calling the following:
public static SqlConnection Connection()
{
string sqlConnection = ConfigurationSettings.AppSettings["SqlConnection"];

//creating of sql connection object
SqlConnection connection = new SqlConnection(sqlConnection);

return(connection)
}

However, when I call this in my code, I get an error stating that the
connection string has not been initialized. One thing I've noticed is
that I've gone to Project1's debug folder (where all of the aseemblies
are) and I notice that the app.config file for the data layer project is
not there.

I am trying to avoid to create the app.config file for Project1 and
passising it's connection string from there. can anyone tell me what I
can do to have this work the way I want it to work?

Any advice or tips will be greatly appreciated.

Nov 16 '05 #4
Thank you all for the great advice and pointers!

Ed_P. wrote:
Hello,

I have the following scenario: I have a solution with 4 projects
Project1 = MainWindow (Windows EXE)
Project2 = PresentationLayer (DLL)
Project3 = BusinessLayer (DLL)
Project4 = DataLayer (DLL)

I have referenced all of the other projects in the first project so that
I could use the objects I've created in them. However, I am running in
to the following situation. In the DataLayer Project, I have created a
class called Database. This database class has a static method called
Connection which retruns a SqlConnection object.

I have created an app.config file for the data layer project and have
added the key called "SqlConnection" for my sql server, here is an exmple:

<appSettings>
<add key="SqlConnection" ...>
</appSettings>

In the DataLayer Static method, I am calling the following:
public static SqlConnection Connection()
{
string sqlConnection =
ConfigurationSettings.AppSettings["SqlConnection"];

//creating of sql connection object
SqlConnection connection = new SqlConnection(sqlConnection);

return(connection)
}

However, when I call this in my code, I get an error stating that the
connection string has not been initialized. One thing I've noticed is
that I've gone to Project1's debug folder (where all of the aseemblies
are) and I notice that the app.config file for the data layer project is
not there.

I am trying to avoid to create the app.config file for Project1 and
passising it's connection string from there. can anyone tell me what I
can do to have this work the way I want it to work?

Any advice or tips will be greatly appreciated.

Nov 16 '05 #5

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

Similar topics

3
by: Geoff Pennington | last post by:
It is really pathetic that I don't know this, but here it is. I have been writing ASP.Net apps for a while, and all configuration information, such as the database connection string, goes in a text...
5
by: Sam Carleton | last post by:
It is my understanding that in .Net the registry is not the prefered place to save application settings. What has Microsoft put in place to replace it? I thought it was the .config file, but I...
2
by: Chris Dunaway | last post by:
I have a web service that references a data class library which performs SQL Server access. Since the web service is also a class library, there is no App.Config, only Web.config. Is Web.Config...
10
by: vwd2005eeb | last post by:
Visual Web Developer 2005 Express Edition Beta I did Build | Build Web site, where are the DLLs? I was expecting to see maybe one dll for each Web page in a directory (maybe still "bin") under...
5
by: feng | last post by:
Hi, We just converted our VB.Net Windows exe project from VS.Net 2002 to VS.Net 2003 and ran into a problem. the MyApp.exe.config file that we use for our customized configuration settings is...
10
by: Brett | last post by:
If I have many hard coded values such as file paths, file names, timeouts, etc, where is the best place to define them? Meaning, in the case something needs changing for example, rather than...
3
by: Richard Lewis Haggard | last post by:
I have a test application that is calling an assembly that reads some strings out of a config file. Normally, this assembly supports a web application and the information can be read just fine....
10
by: Mike9900 | last post by:
Hello, I would like to store application expiration date in a file and store that file in a secure place, so the application can access the file for all the users on that computer. ...
2
by: chris | last post by:
I have created a file, called nunit_project_name.dll.config, within the bin folder of my Nunit project, but Nunit is not able to find the file. Is this is the right location? I can access the...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.