E
Ed_P.
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.
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.