Wednesday, October 23, 2013

Accessing app.config values in class library not working (C#)

In a project that we are working with involves several class libraries. And one of them involves setting/getting the connection string. We simply added an application config file with the connection string in it. However, accessing the key/value of connection string returns null.

One possible solution is to add a Settings file in the class library where you can set the connection string. And to access the connection string value, refer to the code below:
 //Settings is the Settings File.  
 //SalesConnection is the Name of the connection string  
  return new Settings().SalesConnection;  
Here's a similar post regarding Settings File:
Setting app.config in ASP.NET


Post a Comment