----------------------------[ UPDATE ]--------------------------->
I solved the issue by adding the
connsectionString tag to the
app.config in the executable project (not in the app.config inside the DataLayerAccess project) and it works fine.
Do you think I should opt for a different procedure?
------------------------------------------------------------------
I want to connect my application to my DB and I created the connectionString tag with all the info in the
app.config file inside my
DataAccessLayer. When I run the
ConfigurationManager.ConnectionString["valueOfTheNamePropertyInTheConnectionStringSection"].ToString()
I get a "Not set to an Object instance" exception referring to the
ConnectionString.
I think it depends on having multiple
app.config files within my application, for it's composed by multiple projects of type
Library (one for each layer: dataAccess Layer, Business Logic Layer...).
How can I solve this issue and select the only
app.config file I need?
What I have tried:
// the
connectionString section in THE application config file I wanna use:
<connectionStrings>
<add name="DbNameConnection"
connectionString="Data Source = nameOfTheHost; User ID = custom_user; password =
myPassword; Initial Catalog= name_Of_The_DB;/>
</connectionStrings>
// My
DB.cs class file in the DataAccessLayer:
public static string ConnectionString
{
get
{
string connStr = ConfigurationManager.ConnectionStrings["DbNameConnection"].ToString();
}