Click here to Skip to main content
15,886,095 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
----------------------------[ 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();  
  //...
}
Posted
Updated 10-Nov-20 10:56am
v6

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900