I want to retrieve the ConnectionString from the app.config in the DataAccess class library for use in Entity Framework’s .edmx model of the application by using this code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
namespace BusinessLogicAndData
{
public class Connection
{
public static RevenueData GetContext()
{
//ConfigurationManager configManager = new ConfigurationManager();
string conString = ConfigurationManager.ConnectionStrings["RevenueData"].ConnectionString;
RevenueData RDC = new RevenueData(conString);
return RDC;
}
}
}
But each time the program runs, it throws a null reference exception complaining that
object reference is not set to an instance of an object
I have walked through the stack trace of the VS 2010 but I can’t seem to pinpoint the problem. Please any suggestions about the origin of the exception.
You should add connection string to
App.Configof your executable application (not to config in DataAccess library project).