Donate

Accessing App.Config Values In Class Library Not Working In 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
Cheers!

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

How To Insert Or Add Emojis In Microsoft Teams Status Message

TypeScript Error Or Bug: The term 'tsc' is not recognized as the name of a cmdlet, function, script file, or operable program.